1
0
Fork 0

tar/storage: comments

This commit is contained in:
Vincent Batts 2015-02-24 15:36:21 -05:00
parent b1284905d3
commit 89bd581749
2 changed files with 16 additions and 10 deletions

View File

@ -22,6 +22,8 @@ const (
SegmentType SegmentType
) )
// Entry is a the structure for packing and unpacking the information read from
// the Tar archive.
type Entry struct { type Entry struct {
Type Type `json:"type"` Type Type `json:"type"`
Name string `json:"name",omitempty` Name string `json:"name",omitempty`

View File

@ -6,26 +6,24 @@ import (
"io" "io"
) )
// Packer describes the methods to pack Entries to a storage destination
type Packer interface { type Packer interface {
// AddSegment packs the segment bytes provided and returns the position of // AddEntry packs the Entry and returns its position
// the entry
//AddSegment([]byte) (int, error)
// AddFile packs the File provided and returns the position of the entry. The
// Position is set in the stored File.
//AddFile(File) (int, error)
//
AddEntry(e Entry) (int, error) AddEntry(e Entry) (int, error)
} }
// Unpacker describes the methods to read Entries from a source
type Unpacker interface { type Unpacker interface {
// Next returns the next Entry being unpacked, or error, until io.EOF
Next() (*Entry, error) Next() (*Entry, error)
} }
/* TODO(vbatts) figure out a good model for this
type PackUnpacker interface { type PackUnpacker interface {
Packer Packer
Unpacker Unpacker
} }
*/
type jsonUnpacker struct { type jsonUnpacker struct {
r io.Reader r io.Reader
@ -55,8 +53,10 @@ func (jup *jsonUnpacker) Next() (*Entry, error) {
return &e, err return &e, err
} }
// jsonUnpacker writes each entry (SegmentType and FileType) as a json document. // NewJsonUnpacker provides an Unpacker that reads Entries (SegmentType and
// Each entry on a new line. // FileType) as a json document.
//
// Each Entry read are expected to be delimited by new line.
func NewJsonUnpacker(r io.Reader) Unpacker { func NewJsonUnpacker(r io.Reader) Unpacker {
return &jsonUnpacker{ return &jsonUnpacker{
r: r, r: r,
@ -79,6 +79,10 @@ func (jp *jsonPacker) AddEntry(e Entry) (int, error) {
return e.Position, err return e.Position, err
} }
// NewJsonPacker provides an Packer that writes each Entry (SegmentType and
// FileType) as a json document.
//
// The Entries are delimited by new line.
func NewJsonPacker(w io.Writer) Packer { func NewJsonPacker(w io.Writer) Packer {
return &jsonPacker{ return &jsonPacker{
w: w, w: w,