Skip to content

Commit

Permalink
fix: switch constructor args to match storage.New*, make roots plural
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Sep 4, 2023
1 parent 7319768 commit e9e60af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions v2/storage/deferred/deferredcarwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions v2/storage/deferred/deferredcarwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e9e60af

Please sign in to comment.