Documentation
¶
Index ¶
- Variables
- type AbstractBlock
- type Block
- type BlockIterator
- type Iterator
- type MemoryBlock
- type Reader
- type Stream
- func (s *Stream) AppendBlock(b []byte) error
- func (s *Stream) BlockIterator(n int) (*BlockIterator, error)
- func (s *Stream) Close() error
- func (s *Stream) Flush() error
- func (s *Stream) Get(position int) ([]byte, error)
- func (s *Stream) Init() error
- func (s *Stream) Iterator() (*StreamIterator, error)
- func (s *Stream) Reader(n int) (*Reader, error)
- func (s *Stream) Remove() error
- func (s *Stream) Rotate() error
- func (s *Stream) Size() (int64, error)
- func (s *Stream) Write(b []byte) (n int, err error)
- func (s *Stream) WriteObject(obj encoding.BinaryMarshaler) (n int, err error)
- type StreamIterator
- type TempFileBlock
- func (tfb *TempFileBlock) Get(position int) ([]byte, error)
- func (tfb *TempFileBlock) Init(b []byte) error
- func (tfb *TempFileBlock) Iterator() (*BlockIterator, error)
- func (tfb *TempFileBlock) Reader() (*Reader, error)
- func (tfb *TempFileBlock) Remove() error
- func (tfb *TempFileBlock) Size() (int64, error)
- type WriteCloser
- type Writer
Constants ¶
This section is empty.
Variables ¶
var MAXIMUM_SLICE_LENGTH = 400
Functions ¶
This section is empty.
Types ¶
type AbstractBlock ¶
type AbstractBlock struct { Algorithm string `xml:"-" json:"-"` // the compression algorithm used: snappy, gzip, or none. BigEndian bool `xml:"-" json:"-"` // If true, then encode numbers using a big-endian byte order, else encodes using littl-endian byte order. }
AbstractBlock is an abstract struct extended by MemoryBlock and TempFileBlock.
func (AbstractBlock) GetAlgorithm ¶
func (ab AbstractBlock) GetAlgorithm() string
Returns the compress algorithm, which can be: snappy, gzip, or none.
func (AbstractBlock) UseBigEndian ¶
func (ab AbstractBlock) UseBigEndian() bool
UseBigEndian returns true is
type Block ¶
type Block interface { Init(b []byte) error // initialize block Size() (int64, error) // get size of block in bytes Reader() (*Reader, error) // get reader for this block Iterator() (*BlockIterator, error) // get iterator for this block Get(position int) ([]byte, error) // get object at the given position Remove() error // remove block }
Block is an interface for a compressed array of objects in a binary representation
type BlockIterator ¶
BlockIterator is an iterator for reading the data in a block
func (*BlockIterator) Close ¶
func (it *BlockIterator) Close() error
Close closes the iterator's underlying Reader.
func (*BlockIterator) Next ¶
func (it *BlockIterator) Next() ([]byte, error)
Next returns the bytes of the next object in the block, and an error if any.
func (*BlockIterator) Skip ¶
func (it *BlockIterator) Skip(n int) error
Skip advances the iterator forward by "n" objects. Returns an error, if any.
type Iterator ¶
type Iterator interface { Next() ([]byte, error) // returns the current object and advances forward. Close() error // close the underlying Reader. }
Iterator is an interface implemented by StreamIterator and BlockIterator used for iterating through objects.
type MemoryBlock ¶
type MemoryBlock struct { AbstractBlock Bytes []byte `xml:"-" json:"-"` // The compressed block of bytes }
MemoryBlock holds a block of objects in memory. The objects may be compressed using the Algorithm.
func NewMemoryBlock ¶
func NewMemoryBlock(algorithm string, bigEndian bool) *MemoryBlock
NewMemoryBlock returns a new MemoryBlock. Algorithm can be snappy, gzip, or none. If bigEndian is true, then encodes numbers using a big-endian byte order, else encodes using littl-endian byte order.
func (*MemoryBlock) Get ¶
func (mb *MemoryBlock) Get(position int) ([]byte, error)
Get returns the bytes for an object at an arbitrary position, and an error if any. Given the compressed nature of the data, Get starts reading from the beginning every time. If you're iterating through the data, use Iterator. Only use this function for random access.
func (*MemoryBlock) Init ¶
func (mb *MemoryBlock) Init(b []byte) error
Init initializes a block's data.
func (*MemoryBlock) Iterator ¶
func (mb *MemoryBlock) Iterator() (*BlockIterator, error)
Iterator returns a BlockIterator for iterating through the bytes, and an error if any.
func (*MemoryBlock) Reader ¶
func (mb *MemoryBlock) Reader() (*Reader, error)
Reader returns a *Reader for reading the compressed bytes, and an error if any.
func (*MemoryBlock) Size ¶
func (mb *MemoryBlock) Size() (int64, error)
Size returns the number of bytes as an int64.
type Reader ¶
Reader is a struct for easily closing underlying file points once a read is complete. Reader should only be used in situations where an *os.File is only used by a single io.Rreader.
type Stream ¶
type Stream struct { BlockType string `xml:"-" json:"-"` TempDir string `xml:"-" json:"-"` Algorithm string `xml:"-" json:"-"` BigEndian bool `xml:"-" json:"-"` BlockSize int `xml:"-" json:"-"` Blocks []Block `xml:"-" json:"-"` Buffer *bytes.Buffer `xml:"-" json:"-"` Writer Writer `xml:"-" json:"-"` WriteCloser WriteCloser `xml:"-" json:"-"` }
func (*Stream) AppendBlock ¶
func (*Stream) BlockIterator ¶
func (s *Stream) BlockIterator(n int) (*BlockIterator, error)
NewIterator returns a new iterator for the stream
func (*Stream) Iterator ¶
func (s *Stream) Iterator() (*StreamIterator, error)
func (*Stream) WriteObject ¶
func (s *Stream) WriteObject(obj encoding.BinaryMarshaler) (n int, err error)
type StreamIterator ¶
type StreamIterator struct { Blocks []Block `xml:"-" json:"-"` BlockIndex int `xml:"-" json:"-"` BlockIterator *BlockIterator `xml:"-" json:"-"` }
func NewStreamIterator ¶
func NewStreamIterator(blocks []Block) (*StreamIterator, error)
func (*StreamIterator) Next ¶
func (si *StreamIterator) Next() ([]byte, error)
type TempFileBlock ¶
type TempFileBlock struct { AbstractBlock TempDir string `xml:"-" json:"-"` TempDirExpanded string `xml:"-" json:"-"` TempFile string `xml:"-" json:"-"` }
TempFileBlock is struct for reading & writing a compressed block of objects to a temporary file on disk.
func NewTempFileBlock ¶
func NewTempFileBlock(algorithm string, bigEndian bool, tempDir string) *TempFileBlock
NewTempFileBlock returns a new TempFileBlock.
func (*TempFileBlock) Init ¶
func (tfb *TempFileBlock) Init(b []byte) error
Init initializes a TempFileBlock by writing "b" to a temp file in the TempDir directory. The path to the temp file is saved to tfb.TempFile.
func (*TempFileBlock) Iterator ¶
func (tfb *TempFileBlock) Iterator() (*BlockIterator, error)
Iterator returns a BlockIterator for iterating through the blocks data, and an error if any.
func (*TempFileBlock) Reader ¶
func (tfb *TempFileBlock) Reader() (*Reader, error)
Reader returns a Reader for reading the data in the block, and an error if any.
func (*TempFileBlock) Remove ¶
func (tfb *TempFileBlock) Remove() error
Remove removes the temp file from disk.
func (*TempFileBlock) Size ¶
func (tfb *TempFileBlock) Size() (int64, error)
Size returns the number of bytes in the block, by using os.FileInfo.Size(), and an error if any.