-
Notifications
You must be signed in to change notification settings - Fork 336
/
write_blob.go
36 lines (32 loc) · 939 Bytes
/
write_blob.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
package upload
import (
"context"
"encoding/hex"
"io"
"github.com/treeverse/lakefs/pkg/block"
)
type Blob struct {
PhysicalAddress string
RelativePath bool
Checksum string
Size int64
}
func WriteBlob(ctx context.Context, adapter block.Adapter, bucketName, address string, body io.Reader, contentLength int64, opts block.PutOpts) (*Blob, error) {
// handle the upload itself
hashReader := block.NewHashingReader(body, block.HashFunctionMD5, block.HashFunctionSHA256)
err := adapter.Put(ctx, block.ObjectPointer{
StorageNamespace: bucketName,
IdentifierType: block.IdentifierTypeRelative,
Identifier: address,
}, contentLength, hashReader, opts)
if err != nil {
return nil, err
}
checksum := hex.EncodeToString(hashReader.Md5.Sum(nil))
return &Blob{
PhysicalAddress: address,
RelativePath: true,
Checksum: checksum,
Size: hashReader.CopiedSize,
}, nil
}