Documentation
¶
Overview ¶
Package base100 implements base100 encoding and decoding with streaming support. It provides base100 encoding that converts bytes to emoji characters, following the specification from https://github.com/stek29/base100. Each byte is encoded as a 4-byte UTF-8 sequence representing an emoji.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode decodes by base100. This is a legacy function that maintains backward compatibility. Consider using NewStdDecoder().Decode() for new code.
func Encode ¶
Encode encodes by base100. This is a legacy function that maintains backward compatibility. Consider using NewStdEncoder().Encode() for new code.
func NewStreamDecoder ¶
NewStreamDecoder creates a new streaming base100 decoder that reads encoded data from the provided io.Reader. The decoder uses the standard base100 decoding algorithm.
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer) io.WriteCloser
NewStreamEncoder creates a new streaming base100 encoder that writes encoded data to the provided io.Writer. The encoder uses the standard base100 encoding algorithm.
Types ¶
type CorruptInputError ¶
type CorruptInputError int64
CorruptInputError represents an error when corrupted or invalid base100 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 InvalidLengthError ¶
type InvalidLengthError int
InvalidLengthError represents an error when the base100 input length is invalid. Base100 encoding requires each input byte to be represented by exactly 4 bytes, so the input length must be divisible by 4 for proper decoding.
func (InvalidLengthError) Error ¶
func (e InvalidLengthError) Error() string
Error returns a formatted error message describing the invalid length. The message includes the actual length and the requirement for debugging.
type StdDecoder ¶
type StdDecoder struct {
Error error // Error field for storing decoding errors
}
StdDecoder represents a base100 decoder for standard decoding operations. It implements base100 decoding that converts 4-byte UTF-8 sequences back to their original byte values.
func NewStdDecoder ¶
func NewStdDecoder() *StdDecoder
NewStdDecoder creates a new base100 decoder. Base100 decoding uses a fixed algorithm that doesn't require an alphabet lookup.
func (*StdDecoder) Decode ¶
func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)
Decode decodes the given base100-encoded byte slice back to binary data. Each 4-byte sequence is converted back to a single byte using the formula: byte = (byte2 - 0x8f) * 64 + (byte3 - 0x80) - 55 Validates that the first two bytes are 0xf0 and 0x9f respectively.
type StdEncoder ¶
type StdEncoder struct {
Error error // Error field for storing encoding errors
}
StdEncoder represents a base100 encoder for standard encoding operations. It implements base100 encoding that converts each input byte to a 4-byte UTF-8 sequence representing an emoji character.
func NewStdEncoder ¶
func NewStdEncoder() *StdEncoder
NewStdEncoder creates a new base100 encoder. Base100 encoding uses a fixed algorithm that doesn't require an alphabet lookup.
func (*StdEncoder) Encode ¶
func (e *StdEncoder) Encode(src []byte) (dst []byte)
Encode encodes the given byte slice using base100 encoding. Each input byte is converted to a 4-byte sequence: 0xf0, 0x9f, byte2, byte3 where byte2 = ((byte + 55) / 64) + 0x8f and byte3 = (byte + 55) % 64 + 0x80. This creates UTF-8 sequences that represent emoji characters.
type StreamDecoder ¶
type StreamDecoder struct { Error error // Error field for storing decoding errors // contains filtered or unexported fields }
StreamDecoder represents a streaming base100 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 base100 decoding. Reads and decodes base100 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 base100 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 base100 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 base100 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
¶
- base100.go
- errors.go