mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:54:44 +01:00
operations: use built in io.OffsetWriter for go1.20
This commit is contained in:
parent
da244a3709
commit
dd0e5b9a7f
@ -254,27 +254,6 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object,
|
|||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// An offsetWriter maps writes at offset base to offset base+off in the underlying writer.
|
|
||||||
//
|
|
||||||
// Modified from the go source code. Can be replaced with
|
|
||||||
// io.OffsetWriter when we no longer need to support go1.19
|
|
||||||
type offsetWriter struct {
|
|
||||||
w io.WriterAt
|
|
||||||
off int64 // the current offset
|
|
||||||
}
|
|
||||||
|
|
||||||
// newOffsetWriter returns an offsetWriter that writes to w
|
|
||||||
// starting at offset off.
|
|
||||||
func newOffsetWriter(w io.WriterAt, off int64) *offsetWriter {
|
|
||||||
return &offsetWriter{w, off}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *offsetWriter) Write(p []byte) (n int, err error) {
|
|
||||||
n, err = o.w.WriteAt(p, o.off)
|
|
||||||
o.off += int64(n)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// writerAtChunkWriter converts a WriterAtCloser into a ChunkWriter
|
// writerAtChunkWriter converts a WriterAtCloser into a ChunkWriter
|
||||||
type writerAtChunkWriter struct {
|
type writerAtChunkWriter struct {
|
||||||
remote string
|
remote string
|
||||||
@ -296,7 +275,7 @@ func (w *writerAtChunkWriter) WriteChunk(ctx context.Context, chunkNumber int, r
|
|||||||
bytesToWrite = w.size % w.chunkSize
|
bytesToWrite = w.size % w.chunkSize
|
||||||
}
|
}
|
||||||
|
|
||||||
var writer io.Writer = newOffsetWriter(w.writerAt, int64(chunkNumber)*w.chunkSize)
|
var writer io.Writer = io.NewOffsetWriter(w.writerAt, int64(chunkNumber)*w.chunkSize)
|
||||||
if w.writeBufferSize > 0 {
|
if w.writeBufferSize > 0 {
|
||||||
writer = bufio.NewWriterSize(writer, int(w.writeBufferSize))
|
writer = bufio.NewWriterSize(writer, int(w.writeBufferSize))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user