Skip to content

Commit

Permalink
Unexport unused Writer API until it is re-implemented
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
masih authored and mvdan committed Jul 16, 2021
1 parent 6b085bc commit 1a14cef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions v2/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var bulkPadding = make([]byte, bulkPaddingBytesSize)
type (
// padding represents the number of padding bytes.
padding uint64
// Writer writes CAR v2 into a give io.Writer.
Writer struct {
// writer writes CAR v2 into a given io.Writer.
writer struct {
NodeGetter format.NodeGetter
CarV1Padding uint64
IndexPadding uint64
Expand All @@ -31,7 +31,6 @@ type (
roots []cid.Cid
encodedCarV1 *bytes.Buffer
}
WriteOption func(*Writer)
)

// WriteTo writes this padding to the given writer as default value bytes.
Expand All @@ -56,9 +55,9 @@ func (p padding) WriteTo(w io.Writer) (n int64, err error) {
return
}

// NewWriter instantiates a new CAR v2 writer.
func NewWriter(ctx context.Context, ng format.NodeGetter, roots []cid.Cid) *Writer {
return &Writer{
// newWriter instantiates a new CAR v2 writer.
func newWriter(ctx context.Context, ng format.NodeGetter, roots []cid.Cid) *writer {
return &writer{
NodeGetter: ng,
ctx: ctx,
roots: roots,
Expand All @@ -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.
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)
if err != nil {
return
Expand Down Expand Up @@ -113,14 +112,14 @@ func (w *Writer) WriteTo(writer io.Writer) (n int64, err error) {
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)).
WithCarV1Padding(w.CarV1Padding).
WithIndexPadding(w.IndexPadding)
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.
// Right now we copy the bytes since index takes a writer.
// Consider refactoring index to make this process more efficient.
Expand Down Expand Up @@ -185,7 +184,7 @@ func WrapV1(src io.ReadSeeker, dst io.Writer) error {
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.
v2Header := NewHeader(uint64(v1Size))
if _, err := dst.Write(Pragma); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion v2/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestPadding_WriteTo(t *testing.T) {
func TestNewWriter(t *testing.T) {
dagService := dstest.Mock()
wantRoots := generateRootCid(t, dagService)
writer := NewWriter(context.Background(), dagService, wantRoots)
writer := newWriter(context.Background(), dagService, wantRoots)
assert.Equal(t, wantRoots, writer.roots)
}

Expand Down

0 comments on commit 1a14cef

Please sign in to comment.