Browse Source

Merge pull request #148 from agin719/cos-v4-dev

update upload/download opt
master
agin719 3 years ago
committed by GitHub
parent
commit
360bc9b1be
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      object.go
  2. 2
      object_test.go

31
object.go

@ -603,19 +603,20 @@ type Object struct {
// MultiUploadOptions is the option of the multiupload, // MultiUploadOptions is the option of the multiupload,
// ThreadPoolSize default is one // ThreadPoolSize default is one
type MultiUploadOptions struct { type MultiUploadOptions struct {
OptIni *InitiateMultipartUploadOptions
PartSize int64
ThreadPoolSize int
CheckPoint bool
EnableVerification bool
OptIni *InitiateMultipartUploadOptions
PartSize int64
ThreadPoolSize int
CheckPoint bool
DisableChecksum bool
} }
type MultiDownloadOptions struct { type MultiDownloadOptions struct {
Opt *ObjectGetOptions
PartSize int64
ThreadPoolSize int
CheckPoint bool
CheckPointFile string
Opt *ObjectGetOptions
PartSize int64
ThreadPoolSize int
CheckPoint bool
CheckPointFile string
DisableChecksum bool
} }
type MultiDownloadCPInfo struct { type MultiDownloadCPInfo struct {
@ -943,7 +944,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
return nil, nil, err return nil, nil, err
} }
// 校验 // 校验
if s.client.Conf.EnableCRC {
if s.client.Conf.EnableCRC && !opt.DisableChecksum {
fd, err := os.Open(filepath) fd, err := os.Open(filepath)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -972,7 +973,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
Key: name, Key: name,
ETag: rsp.Header.Get("ETag"), ETag: rsp.Header.Get("ETag"),
} }
if rsp != nil && s.client.Conf.EnableCRC {
if rsp != nil && s.client.Conf.EnableCRC && !opt.DisableChecksum {
scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma") scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma")
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64) icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
if icoscrc != localcrc { if icoscrc != localcrc {
@ -1105,7 +1106,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
return v, resp, err return v, resp, err
} }
if resp != nil && s.client.Conf.EnableCRC {
if resp != nil && s.client.Conf.EnableCRC && !opt.DisableChecksum {
scoscrc := resp.Header.Get("x-cos-hash-crc64ecma") scoscrc := resp.Header.Get("x-cos-hash-crc64ecma")
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64) icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
if icoscrc != localcrc { if icoscrc != localcrc {
@ -1225,7 +1226,7 @@ func (s *ObjectService) Download(ctx context.Context, name string, filepath stri
if err != nil { if err != nil {
return rsp, err return rsp, err
} }
if coscrc != "" && s.client.Conf.EnableCRC {
if coscrc != "" && s.client.Conf.EnableCRC && !opt.DisableChecksum {
icoscrc, _ := strconv.ParseUint(coscrc, 10, 64) icoscrc, _ := strconv.ParseUint(coscrc, 10, 64)
fd, err := os.Open(filepath) fd, err := os.Open(filepath)
if err != nil { if err != nil {
@ -1344,7 +1345,7 @@ func (s *ObjectService) Download(ctx context.Context, name string, filepath stri
if opt.CheckPoint { if opt.CheckPoint {
os.Remove(cpfile) os.Remove(cpfile)
} }
if coscrc != "" && s.client.Conf.EnableCRC {
if coscrc != "" && s.client.Conf.EnableCRC && !opt.DisableChecksum {
icoscrc, _ := strconv.ParseUint(coscrc, 10, 64) icoscrc, _ := strconv.ParseUint(coscrc, 10, 64)
fd, err := os.Open(filepath) fd, err := os.Open(filepath)
if err != nil { if err != nil {

2
object_test.go

@ -796,7 +796,7 @@ func TestObjectService_Download(t *testing.T) {
} }
defer os.Remove(filePath) defer os.Remove(filePath)
// 源文件内容 // 源文件内容
totalBytes := int64(1024*1024 + 1230) //1024*1024*9 + 123)
totalBytes := int64(1024*1024*9 + 1230)
b := make([]byte, totalBytes) b := make([]byte, totalBytes)
_, err = rand.Read(b) _, err = rand.Read(b)
newfile.Write(b) newfile.Write(b)

Loading…
Cancel
Save