Documentation
¶
Overview ¶
Package base91 implements base91 encoding and decoding with streaming support. It provides base91 encoding following the specification at http://base91.sourceforge.net, using a 91-character alphabet that excludes space, apostrophe, hyphen, and backslash from the 95 printable ASCII characters for maximum character efficiency.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var StdAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~\""
StdAlphabet is the standard base91 alphabet used for encoding and decoding. It includes uppercase letters A-Z, lowercase letters a-z, digits 0-9, and special characters for a total of 91 characters, excluding space, apostrophe, hyphen, and backslash.
Functions ¶
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming base91 decoder that reads encoded data from the provided io.Reader. The decoder uses the standard base91 alphabet.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer) io.WriteCloser
NewStreamEncoder creates a new streaming base91 encoder that writes encoded data to the provided io.Writer. The encoder uses the standard base91 alphabet.
Types ¶
type AlphabetSizeError ¶
type AlphabetSizeError int
AlphabetSizeError represents an error when the base91 alphabet is invalid. Base91 requires an alphabet of exactly 91 characters for proper encoding and decoding operations. This error occurs when the alphabet length does not meet this requirement.
func (AlphabetSizeError) Error ¶
func (e AlphabetSizeError) Error() string
Error returns a formatted error message describing the invalid alphabet length. The message includes the actual length and the required length for debugging.
type CorruptInputError ¶
type CorruptInputError int64
CorruptInputError represents an error when corrupted or invalid base91 data is detected during decoding. This error occurs when an invalid character is found in the input or when the input data is malformed.
func (CorruptInputError) Error ¶
func (e CorruptInputError) Error() string
Error returns a formatted error message describing the corrupted input. The message includes the position where corruption was detected.
type StdDecoder ¶
type StdDecoder struct { Error error // Error field for storing decoding errors // contains filtered or unexported fields }
StdDecoder represents a base91 decoder for standard decoding operations. It implements base91 decoding following the specification at http://base91.sourceforge.net, providing efficient decoding of base91 strings back to binary data with proper bit unpacking and validation.
func NewStdDecoder ¶
func NewStdDecoder() *StdDecoder
NewStdDecoder creates a new base91 decoder using the standard alphabet. Initializes the decoding lookup table for efficient character mapping. Invalid characters are marked with 0xFF for error detection.
func (*StdDecoder) Decode ¶
func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)
Decode decodes the given base91-encoded byte slice back to binary data. Uses bit-unpacking algorithm to reconstruct the original binary data and validates character validity during decoding.
func (*StdDecoder) DecodedLen ¶
func (d *StdDecoder) DecodedLen(n int) int
DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base91-encoded data.
type StdEncoder ¶
type StdEncoder struct { Error error // Error field for storing encoding errors // contains filtered or unexported fields }
StdEncoder represents a base91 encoder for standard encoding operations. It implements base91 encoding following the specification at http://base91.sourceforge.net, providing efficient encoding of binary data to base91 strings with optimal bit packing.
func NewStdEncoder ¶
func NewStdEncoder() *StdEncoder
NewStdEncoder creates a new base91 encoder using the standard alphabet. Initializes the encoding lookup table for efficient character mapping.
func (*StdEncoder) Encode ¶
func (e *StdEncoder) Encode(src []byte) (dst []byte)
Encode encodes the given byte slice using base91 encoding. Uses a bit-packing algorithm that groups 13 or 14 bits into 16-bit values for optimal encoding efficiency, following the base91 specification.
func (*StdEncoder) EncodedLen ¶
func (e *StdEncoder) EncodedLen(n int) int
EncodedLen returns an upper bound on the length in bytes of the base91 encoding of an input buffer of length n. The true encoded length may be shorter.
type StreamDecoder ¶
type StreamDecoder struct { Error error // Error field for storing decoding errors // contains filtered or unexported fields }
StreamDecoder represents a streaming base91 decoder that implements io.Reader. It provides efficient decoding for large data streams by processing data in chunks and maintaining an internal buffer for partial reads.
func (*StreamDecoder) Read ¶
func (d *StreamDecoder) Read(p []byte) (n int, err error)
Read implements the io.Reader interface for streaming base91 decoding. Reads and decodes base91 data from the underlying reader in chunks. Maintains an internal buffer to handle partial reads efficiently.
type StreamEncoder ¶
type StreamEncoder struct { Error error // Error field for storing encoding errors // contains filtered or unexported fields }
StreamEncoder represents a streaming base91 encoder that implements io.WriteCloser. It provides efficient encoding for large data streams by processing data in chunks and writing encoded output immediately.
func (*StreamEncoder) Close ¶
func (e *StreamEncoder) Close() error
Close implements the io.Closer interface for streaming base91 encoding. Encodes any remaining buffered bytes from the last Write call. This is the only place where we handle cross-Write state.
func (*StreamEncoder) Write ¶
func (e *StreamEncoder) Write(p []byte) (n int, err error)
Write implements the io.Writer interface for streaming base91 encoding. Processes data in chunks while maintaining minimal state for cross-Write calls. This is true streaming - processes data immediately without accumulating large buffers.
Source Files
¶
- base91.go
- errors.go