Documentation
¶
Index ¶
- Constants
- type ByteStream
- func (bs *ByteStream) Close() error
- func (bs *ByteStream) IsEOF() bool
- func (bs *ByteStream) Len() int
- func (bs *ByteStream) Pos() int
- func (bs *ByteStream) Read(b []byte) (n int, err error)
- func (bs *ByteStream) ReadAt(b []byte, off int64) (n int, err error)
- func (bs *ByteStream) ReadUint8(off int64) (uint8, error)
- func (bs *ByteStream) ReadUint16(off int64) (uint16, error)
- func (bs *ByteStream) ReadUint32(off int64) (uint32, error)
- func (bs *ByteStream) ReadUint64(off int64) (uint64, error)
- func (bs *ByteStream) Seek(off int64, whence int) (n int64, err error)
- type FileStream
- func (fs *FileStream) Close() error
- func (fs *FileStream) IsEOF() bool
- func (fs *FileStream) Len() int
- func (fs *FileStream) Pos() int
- func (fs *FileStream) Read(b []byte) (n int, err error)
- func (fs *FileStream) ReadAt(b []byte, off int64) (n int, err error)
- func (fs *FileStream) ReadUint8(off int64) (uint8, error)
- func (fs *FileStream) ReadUint16(off int64) (uint16, error)
- func (fs *FileStream) ReadUint32(off int64) (uint32, error)
- func (fs *FileStream) ReadUint64(off int64) (uint64, error)
- func (fs *FileStream) Seek(off int64, whence int) (n int64, err error)
- type Stream
- type StreamType
Constants ¶
const CacheSize = 8
CacheSize is the current size of the cache we hold when peeking around the stream
const ChunkSize = 1024
ChunkSize is the default chunk size we use to read from files.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteStream ¶
type ByteStream struct {
// contains filtered or unexported fields
}
ByteStream represents an in-memory binary stream.
func NewByteStream ¶
func NewByteStream(b []byte) (*ByteStream, error)
NewByteStream creates a new binary stream from a byte slice (can be memory mapped file).
func (*ByteStream) IsEOF ¶
func (bs *ByteStream) IsEOF() bool
IsEOF checks if we reached the end of the bytestream.
func (*ByteStream) Len ¶
func (bs *ByteStream) Len() int
Len returns the current binary stream size.
func (*ByteStream) Pos ¶
func (bs *ByteStream) Pos() int
Pos returns the current position within the binary stream.
func (*ByteStream) Read ¶
func (bs *ByteStream) Read(b []byte) (n int, err error)
Read len(b) bytes from the underlying stream.
func (*ByteStream) ReadAt ¶
func (bs *ByteStream) ReadAt(b []byte, off int64) (n int, err error)
ReadAt len(b) bytes from the underlying stream at a given offset.
func (*ByteStream) ReadUint8 ¶
func (bs *ByteStream) ReadUint8(off int64) (uint8, error)
ReadUint8 reads a 1 byte little endian unsigned integer.
func (*ByteStream) ReadUint16 ¶
func (bs *ByteStream) ReadUint16(off int64) (uint16, error)
ReadUint16 reads a 2 byte little endian unsigned integer.
func (*ByteStream) ReadUint32 ¶
func (bs *ByteStream) ReadUint32(off int64) (uint32, error)
ReadUint32 reads a 4 byte little endian unsigned integer.
func (*ByteStream) ReadUint64 ¶
func (bs *ByteStream) ReadUint64(off int64) (uint64, error)
ReadUint64 reads a 8 byte little endian unsigned integer.
type FileStream ¶
type FileStream struct {
// contains filtered or unexported fields
}
FileStream represents an in-memory binary stream.
func NewFileStream ¶
func NewFileStream(filename string) (*FileStream, error)
NewFileStream creates a new binary stream from a memory mapped file).
func (*FileStream) IsEOF ¶
func (fs *FileStream) IsEOF() bool
IsEOF checks if we reached the end of the bytestream.
func (*FileStream) Len ¶
func (fs *FileStream) Len() int
Len returns the current binary stream size.
func (*FileStream) Pos ¶
func (fs *FileStream) Pos() int
Pos returns the current position within the binary stream.
func (*FileStream) Read ¶
func (fs *FileStream) Read(b []byte) (n int, err error)
Read len(b) bytes from the underlying stream.
func (*FileStream) ReadAt ¶
func (fs *FileStream) ReadAt(b []byte, off int64) (n int, err error)
ReadAt len(b) bytes from the underlying stream at a given offset.
func (*FileStream) ReadUint8 ¶
func (fs *FileStream) ReadUint8(off int64) (uint8, error)
ReadUint8 reads a 1 byte little endian unsigned integer.
func (*FileStream) ReadUint16 ¶
func (fs *FileStream) ReadUint16(off int64) (uint16, error)
ReadUint16 reads a 2 byte little endian unsigned integer.
func (*FileStream) ReadUint32 ¶
func (fs *FileStream) ReadUint32(off int64) (uint32, error)
ReadUint32 reads a 4 byte little endian unsigned integer.
func (*FileStream) ReadUint64 ¶
func (fs *FileStream) ReadUint64(off int64) (uint64, error)
ReadUint64 reads a 8 byte little endian unsigned integer.
type Stream ¶
type Stream interface {
Len() int // Current stream size
// Small Reader Interface
Read(b []byte) (n int, err error) // Read len(b) from stream.
ReadAt(b []byte, off int64) (n int, err error) // Read len(b) from stream starting at off.
// Seek and position
Pos() int // Return current position in the stream
Seek(off int64, whence int) (n int64, err error) // Move to offset by changing position
// Close the underlying stream.
// While this might seem unncessary for in-memory streams (GC will clean up buffer)
// it is necessary to prevent a mis-use when dealing with file stream.s
Close() error
}
Stream represents the generic interface each implementation should fullfill.
type StreamType ¶
type StreamType int
StreamType represents the stream type we're reading from (a File or Memory)
const ( // UNKNOWN is for unknown stream types. UNKNOWN StreamType = iota // FILE if we're reading from an on-disk file. FILE // MEMORY if we're reading from memory (byte slice) MEMORY )