MCPcopy
hub / github.com/perkeep/perkeep / writeToCache

Function writeToCache

pkg/server/image.go:95–112  ·  view source on GitHub ↗
(ctx context.Context, cache blobserver.Storage, thumbBytes []byte, name string)

Source from the content-addressed store, hash-verified

93}
94
95func writeToCache(ctx context.Context, cache blobserver.Storage, thumbBytes []byte, name string) (br blob.Ref, err error) {
96 tr := bytes.NewReader(thumbBytes)
97 if len(thumbBytes) < constants.MaxBlobSize {
98 br = blob.RefFromBytes(thumbBytes)
99 _, err = blobserver.Receive(ctx, cache, br, tr)
100 } else {
101 // TODO: don't use rolling checksums when writing this. Tell
102 // the filewriter to use 16 MB chunks instead.
103 br, err = schema.WriteFileFromReader(ctx, cache, name, tr)
104 }
105 if err != nil {
106 return br, errors.New("failed to cache " + name + ": " + err.Error())
107 }
108 if imageDebug {
109 log.Printf("Image Cache: saved as %v\n", br)
110 }
111 return br, nil
112}
113
114// cacheScaled saves in the image handler's cache the scaled image bytes
115// in thumbBytes, and puts its blobref in the scaledImage under the key name.

Callers 1

cacheScaledMethod · 0.85

Calls 5

RefFromBytesFunction · 0.92
ReceiveFunction · 0.92
WriteFileFromReaderFunction · 0.92
PrintfMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected