-
Notifications
You must be signed in to change notification settings - Fork 18
/
streams.go
41 lines (37 loc) · 1018 Bytes
/
streams.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
package alluxio
import (
"fmt"
"io"
)
// Close closes a stream.
func (client *Client) Close(id int) error {
return client.post(join(streamsPrefix, fmt.Sprintf("%d", id), close), nil, nil, nil)
}
// Read reads from a stream.
func (client *Client) Read(id int) (io.ReadCloser, error) {
suffix := join(streamsPrefix, fmt.Sprintf("%d", id), read)
resp, err := client.http.Post(client.endpointURL(suffix, nil), "application/json", nil)
if err != nil {
return nil, err
}
if err := check(resp); err != nil {
return nil, err
}
return resp.Body, nil
}
// Write writes to a stream.
func (client *Client) Write(id int, input io.Reader) (int, error) {
suffix := join(streamsPrefix, fmt.Sprintf("%d", id), write)
resp, err := client.http.Post(client.endpointURL(suffix, nil), "application/octet-stream", input)
if err != nil {
return -1, err
}
if err := check(resp); err != nil {
return -1, err
}
var result int
if err := process(resp, &result); err != nil {
return -1, err
}
return result, nil
}