opendrive: implement --opendrive-chunk-size #3707

s3-about
Nick Craig-Wood 2019-11-15 11:22:13 +00:00
parent db39adeb3e
commit 00d30ce0d7
1 changed files with 14 additions and 7 deletions

View File

@ -82,15 +82,24 @@ func init() {
encoder.EncodeLeftSpace | encoder.EncodeLeftSpace |
encoder.EncodeRightSpace | encoder.EncodeRightSpace |
encoder.EncodeInvalidUtf8), encoder.EncodeInvalidUtf8),
}, {
Name: "chunk_size",
Help: `Files will be uploaded in chunks this size.
Note that these chunks are buffered in memory so increasing them will
increase memory use.`,
Default: 10 * fs.MebiByte,
Advanced: true,
}}, }},
}) })
} }
// Options defines the configuration for this backend // Options defines the configuration for this backend
type Options struct { type Options struct {
UserName string `config:"username"` UserName string `config:"username"`
Password string `config:"password"` Password string `config:"password"`
Enc encoder.MultiEncoder `config:"encoding"` Enc encoder.MultiEncoder `config:"encoding"`
ChunkSize fs.SizeSuffix `config:"chunk_size"`
} }
// Fs represents a remote server // Fs represents a remote server
@ -973,15 +982,13 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
// resp.Body.Close() // resp.Body.Close()
// fs.Debugf(nil, "PostOpen: %#v", openResponse) // fs.Debugf(nil, "PostOpen: %#v", openResponse)
// 10 MB chunks size buf := make([]byte, o.fs.opt.ChunkSize)
chunkSize := int64(1024 * 1024 * 10)
buf := make([]byte, int(chunkSize))
chunkOffset := int64(0) chunkOffset := int64(0)
remainingBytes := size remainingBytes := size
chunkCounter := 0 chunkCounter := 0
for remainingBytes > 0 { for remainingBytes > 0 {
currentChunkSize := chunkSize currentChunkSize := int64(o.fs.opt.ChunkSize)
if currentChunkSize > remainingBytes { if currentChunkSize > remainingBytes {
currentChunkSize = remainingBytes currentChunkSize = remainingBytes
} }