From dd0e5b9a7f5c65f0776759ac1bfd9e3e93f5517e Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 13 Jan 2024 16:59:33 +0000 Subject: [PATCH] operations: use built in io.OffsetWriter for go1.20 --- fs/operations/multithread.go | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) 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)) }