Documentation
¶
Overview ¶
Package base32 implements base32 encoding and decoding with streaming support. It provides both standard and hexadecimal base32 alphabets, along with streaming capabilities for efficient processing of large data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var HexAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
HexAlphabet is the hexadecimal base32 alphabet as defined in RFC 4648. It uses digits 0-9 and uppercase letters A-V, providing a more compact representation for hexadecimal data.
var StdAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
StdAlphabet is the standard base32 alphabet as defined in RFC 4648. It uses uppercase letters A-Z and digits 2-7, excluding 0, 1, 8, and 9 to avoid confusion with similar-looking characters.
Functions ¶
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming base32 decoder that reads encoded data from the provided io.Reader. The decoder uses the specified alphabet for decoding.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer, alphabet string) io.WriteCloser
NewStreamEncoder creates a new streaming base32 encoder that writes encoded data to the provided io.Writer. The encoder uses the specified alphabet for encoding. Returns an io.WriteCloser that can be used for streaming base32 encoding.
Types ¶
type AlphabetSizeError ¶
type AlphabetSizeError int
AlphabetSizeError represents an error when the base32 alphabet is invalid. Base32 requires an alphabet of exactly 32 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 base32 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 base32 decoder for standard decoding operations. It wraps the standard library's base32.Encoding to provide a consistent interface with error handling capabilities.
func NewStdDecoder ¶
func NewStdDecoder(alphabet string) *StdDecoder
NewStdDecoder creates a new base32 decoder with the specified alphabet. The alphabet must be a valid base32 alphabet string (exactly 32 characters). Returns a pointer to the newly created StdDecoder.
func (*StdDecoder) Decode ¶
func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)
Decode decodes the given base32-encoded byte slice. Returns the decoded data and any error encountered during decoding. Returns an empty byte slice and nil error if the input is empty. The decoded result is truncated to the actual decoded length.
type StdEncoder ¶
type StdEncoder struct { Error error // Error field for storing encoding errors // contains filtered or unexported fields }
StdEncoder represents a base32 encoder for standard encoding operations. It wraps the standard library's base32.Encoding to provide a consistent interface with error handling capabilities.
func NewStdEncoder ¶
func NewStdEncoder(alphabet string) *StdEncoder
NewStdEncoder creates a new base32 encoder with the specified alphabet. The alphabet must be a valid base32 alphabet string (exactly 32 characters). Returns a pointer to the newly created StdEncoder.
func (*StdEncoder) Encode ¶
func (e *StdEncoder) Encode(src []byte) (dst []byte)
Encode encodes the given byte slice using base32 encoding. Returns an empty byte slice if the input is empty. The encoded result uses the alphabet specified when creating the encoder.
type StreamDecoder ¶
type StreamDecoder struct { Error error // Error field for storing decoding errors // contains filtered or unexported fields }
StreamDecoder represents a streaming base32 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 ¶ added in v1.1.1
func (d *StreamDecoder) Read(p []byte) (n int, err error)
Read implements the io.Reader interface for streaming base32 decoding. Reads and decodes base32 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 base32 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 ¶ added in v1.1.1
func (e *StreamEncoder) Close() error
Close implements the io.Closer interface for streaming base32 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 ¶ added in v1.1.1
func (e *StreamEncoder) Write(p []byte) (n int, err error)
Write implements the io.Writer interface for streaming base32 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
¶
- base32.go
- errors.go