From b4e3332e024ed1f6747cb0a6a92e8b9281b6bf82 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 14 Aug 2023 18:04:42 +0100 Subject: [PATCH] fs: introduces aliases for OpenWriterAtFn and OpenChunkWriterFn --- fs/features.go | 6 ++++++ fs/operations/multithread.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/features.go b/fs/features.go index d722b4412..019dcfcdc 100644 --- a/fs/features.go +++ b/fs/features.go @@ -636,6 +636,9 @@ type OpenWriterAter interface { OpenWriterAt(ctx context.Context, remote string, size int64) (WriterAtCloser, error) } +// OpenWriterAtFn describes the OpenWriterAt function pointer +type OpenWriterAtFn func(ctx context.Context, remote string, size int64) (WriterAtCloser, error) + type OpenChunkWriter interface { // OpenChunkWriter returns the chunk size and a ChunkWriter // @@ -644,6 +647,9 @@ type OpenChunkWriter interface { OpenChunkWriter(ctx context.Context, remote string, src ObjectInfo, options ...OpenOption) (chunkSize int64, writer ChunkWriter, err error) } +// OpenChunkWriterFn describes the OpenChunkWriter function pointer +type OpenChunkWriterFn func(ctx context.Context, remote string, src ObjectInfo, options ...OpenOption) (chunkSize int64, writer ChunkWriter, err error) + type ChunkWriter interface { // WriteChunk will write chunk number with reader bytes, where chunk number >= 0 WriteChunk(chunkNumber int, reader io.ReadSeeker) (bytesWritten int64, err error) diff --git a/fs/operations/multithread.go b/fs/operations/multithread.go index deb7c88ba..f675588bc 100644 --- a/fs/operations/multithread.go +++ b/fs/operations/multithread.go @@ -277,7 +277,8 @@ func (w writerAtChunkWriter) Abort() error { return obj.Remove(w.ctx) } -func openChunkWriterFromOpenWriterAt(openWriterAt func(ctx context.Context, remote string, size int64) (fs.WriterAtCloser, error), chunkSize int64, writeBufferSize int64, f fs.Fs) func(ctx context.Context, remote string, src fs.ObjectInfo, options ...fs.OpenOption) (chunkSizeResult int64, writer fs.ChunkWriter, err error) { +// openChunkWriterFromOpenWriterAt adapts an OpenWriterAtFn into an OpenChunkWriterFn using chunkSize and writeBufferSize +func openChunkWriterFromOpenWriterAt(openWriterAt fs.OpenWriterAtFn, chunkSize int64, writeBufferSize int64, f fs.Fs) fs.OpenChunkWriterFn { return func(ctx context.Context, remote string, src fs.ObjectInfo, options ...fs.OpenOption) (chunkSizeResult int64, writer fs.ChunkWriter, err error) { writerAt, err := openWriterAt(ctx, remote, src.Size()) if err != nil {