This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unpack.go
70 lines (57 loc) · 1.52 KB
/
unpack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package tika
import (
"errors"
"net/http"
)
// UnpackResource represents the structure of our Unpack resource
type UnpackResource struct {
client *Client
endpoint string
}
// Unpack is the entry point for interacting with the Unpack resource
func (c *Client) Unpack() *UnpackResource {
return &UnpackResource{client: c,
endpoint: c.Url + "/unpack",
}
}
// All returns the content and metadata. Text is stored in __TEXT__ file, metadata csv in __METADATA__
func (ur *UnpackResource) All() *UnpackResource {
ur.endpoint += "/all"
return ur
}
// Raw returns the metadata as *http.Response
func (ur *UnpackResource) Raw() ([]byte, error) {
req, err := ur.newRequest()
if err != nil {
return nil, err
}
return ur.client.raw(req)
}
// Tar returns the metadata (and content if using All) as a tarball
func (ur *UnpackResource) Tar() ([]byte, error) {
req, err := ur.newRequest()
req.Header.Set("Accept", "application/x-tar")
if err != nil {
return nil, err
}
return ur.client.raw(req)
}
// Zip returns the metadata (and content if using All) as a zip file
func (ur *UnpackResource) Zip() ([]byte, error) {
req, err := ur.newRequest()
req.Header.Set("Accept", "application/zip")
if err != nil {
return nil, err
}
return ur.client.raw(req)
}
func (ur *UnpackResource) newRequest() (*http.Request, error) {
if ur.client.Document == nil {
return nil, errors.New("need a document")
}
req, err := ur.client.NewRequest(http.MethodPut, ur.endpoint, ur.client.Document)
if err != nil {
return nil, err
}
return req, nil
}