-
Notifications
You must be signed in to change notification settings - Fork 14
/
superfile.go
35 lines (32 loc) · 870 Bytes
/
superfile.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
package bcsgo
import (
// "encoding/json"
"fmt"
// "io"
// "net/http"
"strings"
)
type Superfile struct {
Object
Objects []*Object
}
func (this *Superfile) putSuperfileUrl() string {
return this.putUrl() + "&superfile=1"
}
func (this *Superfile) Put() error {
link := this.putSuperfileUrl()
parts := make([]string, 0)
for i, item := range this.Objects {
parts = append(parts, fmt.Sprintf(`"part_%d": {"url": "%s", "etag":"%s"}`, i, item.refStr(), item.ContentMD5))
}
partsStr := strings.Join(parts, ",")
meta := fmt.Sprintf(`{"object_list": {%s}}`, partsStr)
reader := strings.NewReader(meta)
resp, _, err := this.bucket.bcs.httpClient.Put(link, reader, int64(len(meta)), nil)
err = mergeResponseError(err, resp)
if err == nil {
this.ContentMD5 = resp.Header.Get(HEADER_ETAG)
this.VersionKey = resp.Header.Get(HEADER_VERSION)
}
return err
}