MCPcopy
hub / github.com/perkeep/perkeep / EnumerateBlobsOpts

Method EnumerateBlobsOpts

pkg/client/enumerate.go:62–141  ·  view source on GitHub ↗

EnumerateBlobsOpts sends blobs to the provided channel, as directed by opts. The channel will be closed, regardless of whether an error is returned.

(ctx context.Context, ch chan<- blob.SizedRef, opts EnumerateOpts)

Source from the content-addressed store, hash-verified

60// EnumerateBlobsOpts sends blobs to the provided channel, as directed by opts.
61// The channel will be closed, regardless of whether an error is returned.
62func (c *Client) EnumerateBlobsOpts(ctx context.Context, ch chan<- blob.SizedRef, opts EnumerateOpts) error {
63 defer close(ch)
64 if opts.After != "" && opts.MaxWait != 0 {
65 return errors.New("client error: it's invalid to use enumerate After and MaxWaitSec together")
66 }
67 pfx, err := c.prefix()
68 if err != nil {
69 return err
70 }
71
72 error := func(msg string, e error) error {
73 err := fmt.Errorf("client enumerate error: %s: %v", msg, e)
74 c.printf("%v", err)
75 return err
76 }
77
78 nSent := 0
79 keepGoing := true
80 after := opts.After
81 for keepGoing {
82 waitSec := 0
83 if after == "" {
84 if opts.MaxWait > 0 {
85 waitSec = int(opts.MaxWait.Seconds())
86 if waitSec == 0 {
87 waitSec = 1
88 }
89 }
90 }
91 url_ := fmt.Sprintf("%s/camli/enumerate-blobs?after=%s&limit=%d&maxwaitsec=%d",
92 pfx, url.QueryEscape(after), enumerateBatchSize, waitSec)
93 req := c.newRequest(ctx, "GET", url_)
94 resp, err := c.httpClient.Do(req)
95 if err != nil {
96 return error("http request", err)
97 }
98
99 json, err := c.responseJSONMap("enumerate-blobs", resp)
100 if err != nil {
101 return error("stat json parse error", err)
102 }
103
104 blobs, ok := getJSONMapArray(json, "blobs")
105 if !ok {
106 return error("response JSON didn't contain 'blobs' array", nil)
107 }
108 for _, v := range blobs {
109 itemJSON, ok := v.(map[string]interface{})
110 if !ok {
111 return error("item in 'blobs' was malformed", nil)
112 }
113 blobrefStr, ok := getJSONMapString(itemJSON, "blobRef")
114 if !ok {
115 return error("item in 'blobs' was missing string 'blobRef'", nil)
116 }
117 size, ok := getJSONMapUint32(itemJSON, "size")
118 if !ok {
119 return error("item in 'blobs' was missing numeric 'size'", nil)

Callers 3

SimpleEnumerateBlobsMethod · 0.95
EnumerateBlobsMethod · 0.95
EnumerateBlobsMethod · 0.80

Calls 10

prefixMethod · 0.95
printfMethod · 0.95
newRequestMethod · 0.95
responseJSONMapMethod · 0.95
ParseFunction · 0.92
errorFunction · 0.85
getJSONMapArrayFunction · 0.85
getJSONMapStringFunction · 0.85
getJSONMapUint32Function · 0.85
ErrMethod · 0.45

Tested by

no test coverage detected