Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

operations: use built in io.OffsetWriter for go1.20

Nick Craig-Wooddd0e5b9a7f5c
diff --git a/fs/operations/multithread.go b/fs/operations/multithread.go
index 46e66dfa4..9cc5ce0fe 100644
--- a/fs/operations/multithread.go
+++ b/fs/operations/multithread.go
@@ -254,27 +254,6 @@ func multiThreadCopy(ctx context.Context, f fs.Fs, remote string, src fs.Object,
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
type writerAtChunkWriter struct {
remote string
@@ -296,7 +275,7 @@ func (w *writerAtChunkWriter) WriteChunk(ctx context.Context, chunkNumber int, r
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 {
writer = bufio.NewWriterSize(writer, int(w.writeBufferSize))
}