-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbytes.go
More file actions
43 lines (36 loc) · 1.19 KB
/
bytes.go
File metadata and controls
43 lines (36 loc) · 1.19 KB
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
package api
import (
"context"
"io"
"net/http"
"strconv"
"github.com/ethersphere/bee/v2/pkg/swarm"
)
// BytesService represents Bee's Bytes service
type BytesService service
// Download downloads data from the node
func (b *BytesService) Download(ctx context.Context, a swarm.Address, opts *DownloadOptions) (resp io.ReadCloser, err error) {
return b.client.requestData(ctx, http.MethodGet, "/"+apiVersion+"/bytes/"+a.String(), nil, opts)
}
// BytesUploadResponse represents Upload's response
type BytesUploadResponse struct {
Reference swarm.Address `json:"reference"`
}
// Upload uploads bytes to the node
func (b *BytesService) Upload(ctx context.Context, data io.Reader, o UploadOptions) (BytesUploadResponse, error) {
var resp BytesUploadResponse
h := http.Header{}
if o.Pin {
h.Add(swarmPinHeader, "true")
}
if o.Tag != 0 {
h.Add(swarmTagHeader, strconv.FormatUint(o.Tag, 10))
}
h.Add(deferredUploadHeader, strconv.FormatBool(!o.Direct))
h.Add(postageStampBatchHeader, o.BatchID)
if o.RLevel != nil {
h.Add(swarmRedundancyLevelHeader, strconv.Itoa(int(*o.RLevel)))
}
err := b.client.requestWithHeader(ctx, http.MethodPost, "/"+apiVersion+"/bytes", h, data, &resp)
return resp, err
}