Documentation
¶
Overview ¶
Package base45 implements base45 encoding and decoding with streaming support. It provides base45 encoding as defined in RFC 9285, which is designed for efficient encoding of binary data using a 45-character alphabet.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var StdAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
StdAlphabet is the standard base45 alphabet as defined in RFC 9285. It includes digits 0-9, uppercase letters A-Z, and special characters space, $, %, *, +, -, ., /, and : for a total of 45 characters.
Functions ¶
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming base45 decoder that reads encoded data from the provided io.Reader. The decoder uses the standard base45 alphabet.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer) io.WriteCloser
NewStreamEncoder creates a new streaming base45 encoder that writes encoded data to the provided io.Writer. The encoder uses the standard base45 alphabet. Returns an io.WriteCloser that can be used for streaming base45 encoding.
Types ¶
type CorruptInputError ¶
type CorruptInputError int64
CorruptInputError represents an error when corrupted or invalid base45 data is detected during decoding. This error occurs when the decoded value exceeds the expected range 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 InvalidCharacterError ¶
type InvalidCharacterError struct {
Char rune // The invalid character that was found
Position int // The position of the invalid character in the input
}
InvalidCharacterError represents an error when an invalid character is found in base45 input. This error occurs when a character is not part of the base45 alphabet or is outside the valid range.
func (InvalidCharacterError) Error ¶
func (e InvalidCharacterError) Error() string
Error returns a formatted error message describing the invalid character. The message includes the character and its position for debugging.
type InvalidLengthError ¶
type InvalidLengthError struct {
Length int // The invalid input length
Mod int // The actual modulo value that caused the error
}
InvalidLengthError represents an error when the base45 input length is invalid. Base45 requires input length to be congruent to 0 or 2 modulo 3. This error occurs when the input length does not meet this requirement.
func (InvalidLengthError) Error ¶
func (e InvalidLengthError) Error() string
Error returns a formatted error message describing the invalid input length. The message includes the actual length and modulo value for debugging.
type StdDecoder ¶
type StdDecoder struct {
Error error // Error field for storing decoding errors
// contains filtered or unexported fields
}
StdDecoder represents a base45 decoder for standard decoding operations. It implements the base45 decoding algorithm as specified in RFC 9285, providing efficient decoding of base45 strings back to binary data.
func NewStdDecoder ¶
func NewStdDecoder() *StdDecoder
NewStdDecoder creates a new base45 decoder using the standard alphabet. Uses the pre-initialized global decode map for better performance.
func (*StdDecoder) Decode ¶
func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)
Decode decodes the given base45-encoded byte slice back to binary data. Validates input length (must be congruent to 0 or 2 modulo 3) and character validity.
type StdEncoder ¶
type StdEncoder struct {
Error error // Error field for storing encoding errors
// contains filtered or unexported fields
}
StdEncoder represents a base45 encoder for standard encoding operations. It implements the base45 encoding algorithm as specified in RFC 9285, providing efficient encoding of binary data to base45 strings.
func NewStdEncoder ¶
func NewStdEncoder() *StdEncoder
NewStdEncoder creates a new base45 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 base45 encoding as per RFC 9285. Base45 encodes 2 bytes in 3 characters, or 1 byte in 2 characters. The encoding process handles both even and odd-length inputs efficiently.
type StreamDecoder ¶
type StreamDecoder struct {
Error error // Error field for storing decoding errors
// contains filtered or unexported fields
}
StreamDecoder represents a streaming base45 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 base45 decoding. Reads and decodes base45 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 base45 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 base45 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 base45 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
¶
- base45.go
- errors.go