Commit 1a14cefa authored by Masih H. Derkani's avatar Masih H. Derkani Committed by Daniel Martí

Unexport unused `Writer` API until it is re-implemented

Unexport the CARv2 writer API until it is reimplemented using WriterAt
or WriteSeeker to be more efficient. This API is not used anyway and we
can postpone releasing it until SelectiveCar writer API is figured out.
For now we unexport it to carry on with interface finalization and alpha
release.
parent 6b085bcb
...@@ -21,8 +21,8 @@ var bulkPadding = make([]byte, bulkPaddingBytesSize) ...@@ -21,8 +21,8 @@ var bulkPadding = make([]byte, bulkPaddingBytesSize)
type ( type (
// padding represents the number of padding bytes. // padding represents the number of padding bytes.
padding uint64 padding uint64
// Writer writes CAR v2 into a give io.Writer. // writer writes CAR v2 into a given io.Writer.
Writer struct { writer struct {
NodeGetter format.NodeGetter NodeGetter format.NodeGetter
CarV1Padding uint64 CarV1Padding uint64
IndexPadding uint64 IndexPadding uint64
...@@ -31,7 +31,6 @@ type ( ...@@ -31,7 +31,6 @@ type (
roots []cid.Cid roots []cid.Cid
encodedCarV1 *bytes.Buffer encodedCarV1 *bytes.Buffer
} }
WriteOption func(*Writer)
) )
// WriteTo writes this padding to the given writer as default value bytes. // WriteTo writes this padding to the given writer as default value bytes.
...@@ -56,9 +55,9 @@ func (p padding) WriteTo(w io.Writer) (n int64, err error) { ...@@ -56,9 +55,9 @@ func (p padding) WriteTo(w io.Writer) (n int64, err error) {
return return
} }
// NewWriter instantiates a new CAR v2 writer. // newWriter instantiates a new CAR v2 writer.
func NewWriter(ctx context.Context, ng format.NodeGetter, roots []cid.Cid) *Writer { func newWriter(ctx context.Context, ng format.NodeGetter, roots []cid.Cid) *writer {
return &Writer{ return &writer{
NodeGetter: ng, NodeGetter: ng,
ctx: ctx, ctx: ctx,
roots: roots, roots: roots,
...@@ -67,7 +66,7 @@ func NewWriter(ctx context.Context, ng format.NodeGetter, roots []cid.Cid) *Writ ...@@ -67,7 +66,7 @@ func NewWriter(ctx context.Context, ng format.NodeGetter, roots []cid.Cid) *Writ
} }
// WriteTo writes the given root CIDs according to CAR v2 specification. // WriteTo writes the given root CIDs according to CAR v2 specification.
func (w *Writer) WriteTo(writer io.Writer) (n int64, err error) { func (w *writer) WriteTo(writer io.Writer) (n int64, err error) {
_, err = writer.Write(Pragma) _, err = writer.Write(Pragma)
if err != nil { if err != nil {
return return
...@@ -113,14 +112,14 @@ func (w *Writer) WriteTo(writer io.Writer) (n int64, err error) { ...@@ -113,14 +112,14 @@ func (w *Writer) WriteTo(writer io.Writer) (n int64, err error) {
return return
} }
func (w *Writer) writeHeader(writer io.Writer, carV1Len int) (int64, error) { func (w *writer) writeHeader(writer io.Writer, carV1Len int) (int64, error) {
header := NewHeader(uint64(carV1Len)). header := NewHeader(uint64(carV1Len)).
WithCarV1Padding(w.CarV1Padding). WithCarV1Padding(w.CarV1Padding).
WithIndexPadding(w.IndexPadding) WithIndexPadding(w.IndexPadding)
return header.WriteTo(writer) return header.WriteTo(writer)
} }
func (w *Writer) writeIndex(writer io.Writer, carV1 []byte) (int64, error) { func (w *writer) writeIndex(writer io.Writer, carV1 []byte) (int64, error) {
// TODO avoid recopying the bytes by refactoring index once it is integrated here. // TODO avoid recopying the bytes by refactoring index once it is integrated here.
// Right now we copy the bytes since index takes a writer. // Right now we copy the bytes since index takes a writer.
// Consider refactoring index to make this process more efficient. // Consider refactoring index to make this process more efficient.
...@@ -185,7 +184,7 @@ func WrapV1(src io.ReadSeeker, dst io.Writer) error { ...@@ -185,7 +184,7 @@ func WrapV1(src io.ReadSeeker, dst io.Writer) error {
return err return err
} }
// Similar to the Writer API, write all components of a CARv2 to the // Similar to the writer API, write all components of a CARv2 to the
// destination file: Pragma, Header, CARv1, Index. // destination file: Pragma, Header, CARv1, Index.
v2Header := NewHeader(uint64(v1Size)) v2Header := NewHeader(uint64(v1Size))
if _, err := dst.Write(Pragma); err != nil { if _, err := dst.Write(Pragma); err != nil {
......
...@@ -60,7 +60,7 @@ func TestPadding_WriteTo(t *testing.T) { ...@@ -60,7 +60,7 @@ func TestPadding_WriteTo(t *testing.T) {
func TestNewWriter(t *testing.T) { func TestNewWriter(t *testing.T) {
dagService := dstest.Mock() dagService := dstest.Mock()
wantRoots := generateRootCid(t, dagService) wantRoots := generateRootCid(t, dagService)
writer := NewWriter(context.Background(), dagService, wantRoots) writer := newWriter(context.Background(), dagService, wantRoots)
assert.Equal(t, wantRoots, writer.roots) assert.Equal(t, wantRoots, writer.roots)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment