From e9e60af41393d3a7db6015b178fdcf4b5688be9f Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Sat, 2 Sep 2023 20:35:37 +1000 Subject: [PATCH] fix: switch constructor args to match storage.New*, make roots plural --- v2/storage/deferred/deferredcarwriter.go | 12 ++++++------ v2/storage/deferred/deferredcarwriter_test.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/v2/storage/deferred/deferredcarwriter.go b/v2/storage/deferred/deferredcarwriter.go index dfcd952..d6d5f10 100644 --- a/v2/storage/deferred/deferredcarwriter.go +++ b/v2/storage/deferred/deferredcarwriter.go @@ -41,7 +41,7 @@ var _ io.Closer = (*DeferredCarWriter)(nil) // HTTP headers in the assumption that the beginning of a valid CAR is about to // be streamed. type DeferredCarWriter struct { - root cid.Cid + roots []cid.Cid outPath string outStream io.Writer @@ -58,8 +58,8 @@ type DeferredCarWriter struct { // // No options are supplied to carstorage.NewWritable by default, add // the car.WriteAsCarV1(true) option to write a CARv1 file. -func NewDeferredCarWriterForPath(root cid.Cid, outPath string, opts ...carv2.Option) *DeferredCarWriter { - return &DeferredCarWriter{root: root, outPath: outPath, opts: opts} +func NewDeferredCarWriterForPath(outPath string, roots []cid.Cid, opts ...carv2.Option) *DeferredCarWriter { + return &DeferredCarWriter{roots: roots, outPath: outPath, opts: opts} } // NewDeferredCarWriterForStream creates a DeferredCarWriter that will write to @@ -69,9 +69,9 @@ func NewDeferredCarWriterForPath(root cid.Cid, outPath string, opts ...carv2.Opt // The car.WriteAsCarV1(true) option will be supplied by default to // carstorage.NewWritable as CARv2 is not a valid streaming format due to the // header. -func NewDeferredCarWriterForStream(root cid.Cid, outStream io.Writer, opts ...carv2.Option) *DeferredCarWriter { +func NewDeferredCarWriterForStream(outStream io.Writer, roots []cid.Cid, opts ...carv2.Option) *DeferredCarWriter { opts = append([]carv2.Option{carv2.WriteAsCarV1(true)}, opts...) - return &DeferredCarWriter{root: root, outStream: outStream, opts: opts} + return &DeferredCarWriter{roots: roots, outStream: outStream, opts: opts} } // OnPut will call a callback when each Put() operation is started. The argument @@ -140,7 +140,7 @@ func (dcw *DeferredCarWriter) writer() (carstorage.WritableCar, error) { dcw.f = openedFile outStream = openedFile } - w, err := carstorage.NewWritable(outStream, []cid.Cid{dcw.root}, dcw.opts...) + w, err := carstorage.NewWritable(outStream, dcw.roots, dcw.opts...) if err != nil { return nil, err } diff --git a/v2/storage/deferred/deferredcarwriter_test.go b/v2/storage/deferred/deferredcarwriter_test.go index 790cde4..2a5994f 100644 --- a/v2/storage/deferred/deferredcarwriter_test.go +++ b/v2/storage/deferred/deferredcarwriter_test.go @@ -35,7 +35,7 @@ func TestDeferredCarWriterForPath(t *testing.T) { if version == 1 { opts = append(opts, carv2.WriteAsCarV1(true)) } - cw := deferred.NewDeferredCarWriterForPath(testCid1, tmpFile, opts...) + cw := deferred.NewDeferredCarWriterForPath(tmpFile, []cid.Cid{testCid1}, opts...) _, err := os.Stat(tmpFile) req.True(os.IsNotExist(err)) @@ -94,11 +94,11 @@ func TestDeferredCarWriter(t *testing.T) { tmpFile := t.TempDir() + "/test.car" if tc == "path" { - cw = deferred.NewDeferredCarWriterForPath(testCid1, tmpFile, carv2.WriteAsCarV1(true)) + cw = deferred.NewDeferredCarWriterForPath(tmpFile, []cid.Cid{testCid1}, carv2.WriteAsCarV1(true)) _, err := os.Stat(tmpFile) require.True(t, os.IsNotExist(err)) } else { - cw = deferred.NewDeferredCarWriterForStream(testCid1, &buf) + cw = deferred.NewDeferredCarWriterForStream(&buf, []cid.Cid{testCid1}) require.Equal(t, buf.Len(), 0) } @@ -169,7 +169,7 @@ func TestDeferredCarWriterPutCb(t *testing.T) { testCid2, testData2 := randBlock() var buf bytes.Buffer - cw := deferred.NewDeferredCarWriterForStream(testCid1, &buf) + cw := deferred.NewDeferredCarWriterForStream(&buf, []cid.Cid{testCid1}) var pc1 int cw.OnPut(func(ii int) {