Documentation
¶
Overview ¶
Package base64 implements base64 encoding and decoding with streaming support. It provides both standard and URL-safe base64 alphabets, along with streaming capabilities for efficient processing of large data. Base64 encoding follows RFC 4648 standard for binary-to-text encoding.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var StdAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
StdAlphabet is the standard base64 alphabet as defined in RFC 4648. It uses uppercase letters A-Z, lowercase letters a-z, digits 0-9, plus sign (+), and forward slash (/) for a total of 64 characters. This is the most commonly used base64 alphabet for general purpose encoding.
var URLAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
URLAlphabet is the URL-safe base64 alphabet as defined in RFC 4648. It uses uppercase letters A-Z, lowercase letters a-z, digits 0-9, minus sign (-), and underscore (_) for a total of 64 characters. This alphabet is safe for use in URLs and filenames as it avoids characters that have special meaning in these contexts.
Functions ¶
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming base64 decoder that reads encoded data from the provided io.Reader. The decoder uses the specified alphabet for decoding. The decoder automatically handles padding and invalid characters.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer, alphabet string) io.WriteCloser
NewStreamEncoder creates a new streaming base64 encoder that writes encoded data to the provided io.Writer. The encoder uses the specified alphabet for encoding. The encoder automatically handles padding when Close() is called.
Types ¶
type AlphabetSizeError ¶
type AlphabetSizeError int
AlphabetSizeError represents an error when the base64 alphabet is invalid. Base64 requires an alphabet of exactly 64 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 base64 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 base64 decoder for standard decoding operations. It wraps the standard library's base64.Encoding to provide a consistent interface with error handling capabilities and support for custom alphabets.
func NewStdDecoder ¶
func NewStdDecoder(alphabet string) *StdDecoder
NewStdDecoder creates a new base64 decoder with the specified alphabet. The alphabet must be a valid base64 alphabet string (exactly 64 characters). Common choices are StdAlphabet for standard decoding or URLAlphabet for URL-safe decoding.
type StdEncoder ¶
type StdEncoder struct {
Error error // Error field for storing encoding errors
// contains filtered or unexported fields
}
StdEncoder represents a base64 encoder for standard encoding operations. It wraps the standard library's base64.Encoding to provide a consistent interface with error handling capabilities and support for custom alphabets.
func NewStdEncoder ¶
func NewStdEncoder(alphabet string) *StdEncoder
NewStdEncoder creates a new base64 encoder with the specified alphabet. The alphabet must be a valid base64 alphabet string (exactly 64 characters). Common choices are StdAlphabet for standard encoding or URLAlphabet for URL-safe encoding.
func (*StdEncoder) Encode ¶
func (e *StdEncoder) Encode(src []byte) (dst []byte)
Encode encodes the given byte slice using base64 encoding. The encoded result uses the alphabet specified when creating the encoder. The encoding process handles padding automatically according to RFC 4648.
type StreamDecoder ¶
type StreamDecoder struct {
Error error // Error field for storing decoding errors
// contains filtered or unexported fields
}
StreamDecoder represents a streaming base64 decoder that implements io.Reader. It provides efficient decoding for large data streams by processing data in chunks rather than loading everything into memory at once.
type StreamEncoder ¶
type StreamEncoder struct {
Error error // Error field for storing encoding errors
// contains filtered or unexported fields
}
StreamEncoder represents a streaming base64 encoder that implements io.WriteCloser. It provides efficient encoding for large data streams by processing data in chunks rather than loading everything into memory at once.
Source Files
¶
- base64.go
- errors.go