base62

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package base62 implements base62 encoding and decoding with streaming support. It provides base62 encoding strictly following Python base62 library specifications, using a 62-character alphabet including digits 0-9, uppercase A-Z, and lowercase a-z.

Index

Constants

This section is empty.

Variables

View Source
var StdAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

StdAlphabet is the standard base62 alphabet used for encoding and decoding. It includes digits 0-9, uppercase letters A-Z, and lowercase letters a-z for a total of 62 characters, providing maximum character efficiency.

Functions

func NewStreamDecoder

func NewStreamDecoder(r io.Reader) io.Reader

NewStreamDecoder creates a new streaming base62 decoder that reads encoded data from the provided io.Reader. The decoder uses the standard base62 alphabet.

func NewStreamEncoder

func NewStreamEncoder(w io.Writer) io.WriteCloser

NewStreamEncoder creates a new streaming base62 encoder that writes encoded data to the provided io.Writer. The encoder uses the standard base62 alphabet.

Types

type AlphabetSizeError

type AlphabetSizeError int

AlphabetSizeError represents an error when the base62 alphabet is invalid. Base62 requires an alphabet of exactly 62 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 base62 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 base62 decoder for standard decoding operations. It implements base62 decoding following Python base62 library specifications, providing efficient decoding of base62 strings back to binary data with proper handling of leading zeros.

func NewStdDecoder

func NewStdDecoder() *StdDecoder

NewStdDecoder creates a new base62 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 base62-encoded byte slice back to binary data. Handles leading zeros pattern ("0" + character) and validates character validity. Uses big.Int arithmetic for large number handling.

type StdEncoder

type StdEncoder struct {
	Error error // Error field for storing encoding errors
	// contains filtered or unexported fields
}

StdEncoder represents a base62 encoder for standard encoding operations. It implements base62 encoding following Python base62 library specifications, providing efficient encoding of binary data to base62 strings with proper handling of leading zeros.

func NewStdEncoder

func NewStdEncoder() *StdEncoder

NewStdEncoder creates a new base62 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 base62 encoding. Handles leading zeros specially by encoding them as "0" + character pairs. The encoding process uses big.Int arithmetic for large number handling.

type StreamDecoder

type StreamDecoder struct {
	Error error // Error field for storing decoding errors
	// contains filtered or unexported fields
}

StreamDecoder represents a streaming base62 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 base62 decoding. Reads and decodes base62 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 base62 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 base62 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 base62 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

  • base62.go
  • errors.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL