MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / UploadFile

Method UploadFile

pkg/casclient/uploader.go:39–60  ·  view source on GitHub ↗

1MB Uploads a given file to a CAS server

(ctx context.Context, filepath string)

Source from the content-addressed store, hash-verified

37
38// Uploads a given file to a CAS server
39func (c *Client) UploadFile(ctx context.Context, filepath string) (*UpDownStatus, error) {
40 // open file and calculate digest
41 f, err := os.Open(filepath)
42 if err != nil {
43 return nil, fmt.Errorf("can't open file to upload: %w", err)
44 }
45 defer f.Close()
46
47 hash, _, err := cr_v1.SHA256(f)
48 if err != nil {
49 return nil, fmt.Errorf("generating digest: %w", err)
50 }
51
52 // Since we have already iterated on the file to calculate the digest
53 // we need to rewind the file pointer
54 _, err = f.Seek(0, io.SeekStart)
55 if err != nil {
56 return nil, fmt.Errorf("rewinding file pointer: %w", err)
57 }
58
59 return c.Upload(ctx, f, path.Base(filepath), hash.String())
60}
61
62func (c *Client) Upload(ctx context.Context, r io.Reader, filename, digest string) (*UpDownStatus, error) {
63 // Check digest format, including the algorithm and the hex portion

Callers

nothing calls this directly

Calls 3

UploadMethod · 0.95
StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected