Documentation
¶
Overview ¶
Package base64 implements RFC 4648 encoding with SIMD acceleration for media payloads. Its Encoding API follows encoding/base64.
Index ¶
- Constants
- Variables
- func AppendDataURL(dst []byte, mediaType string, src []byte) []byte
- func EncodeDataURL(mediaType string, src []byte) string
- func NewDecoder(enc *Encoding, r io.Reader) io.Reader
- func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
- type CorruptInputError
- type Encoding
- func (e *Encoding) AppendDecode(dst, src []byte) ([]byte, error)
- func (e *Encoding) AppendEncode(dst, src []byte) []byte
- func (e *Encoding) Decode(dst, src []byte) (int, error)
- func (e *Encoding) DecodeString(s string) ([]byte, error)
- func (e *Encoding) DecodedLen(n int) int
- func (e *Encoding) Encode(dst, src []byte)
- func (e *Encoding) EncodeToString(src []byte) string
- func (e *Encoding) EncodedLen(n int) int
- func (e Encoding) Strict() *Encoding
- func (e *Encoding) ValidateString(s string) (decodedLen int, err error)
- func (e Encoding) WithPadding(padding rune) *Encoding
Constants ¶
const ( StdPadding = std.StdPadding NoPadding = std.NoPadding )
Variables ¶
var ( StdEncoding = NewEncoding(standardAlphabet) URLEncoding = NewEncoding(urlAlphabet) RawStdEncoding = StdEncoding.WithPadding(NoPadding) RawURLEncoding = URLEncoding.WithPadding(NoPadding) )
Functions ¶
func AppendDataURL ¶
AppendDataURL appends a standard padded base64 data URL to dst. mediaType must be a valid MIME type supplied by the caller.
func EncodeDataURL ¶
EncodeDataURL returns data:<mediaType>;base64,<payload> in one allocation. mediaType must be a valid MIME type supplied by the caller, such as image/png.
func NewDecoder ¶
NewDecoder returns the standard library's streaming decoder for enc.
func NewEncoder ¶
func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
NewEncoder returns a streaming encoder. Close it to flush the final block. Streaming currently uses the standard library's buffered implementation.
Types ¶
type CorruptInputError ¶
type CorruptInputError = std.CorruptInputError
CorruptInputError reports the byte offset of invalid base64 input.
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
Encoding describes a base64 alphabet, padding and strict decoding rules. Configured encodings can be shared by concurrent callers.
func NewEncoding ¶
NewEncoding creates an encoding from 64 distinct bytes. It panics for invalid alphabets according to encoding/base64.NewEncoding.
func (*Encoding) AppendDecode ¶
AppendDecode appends decoded bytes to dst, including the valid prefix when the input is corrupt.
func (*Encoding) AppendEncode ¶
AppendEncode appends the encoding of src to dst.
func (*Encoding) Decode ¶
Decode writes decoded bytes to dst and returns their count. On corrupt input, it returns the valid prefix and a CorruptInputError at the original offset. CR and LF are ignored. dst must have enough space for the decoded output.
func (*Encoding) DecodeString ¶
DecodeString decodes s without making a temporary copy of its input.
func (*Encoding) DecodedLen ¶
DecodedLen returns the maximum decoded length for n encoded bytes.
func (*Encoding) Encode ¶
Encode writes EncodedLen(len(src)) bytes to dst. A short dst causes a panic.
func (*Encoding) EncodeToString ¶
EncodeToString returns an immutable encoding of src using one allocation.
func (*Encoding) EncodedLen ¶
EncodedLen returns the number of bytes needed to encode n source bytes.
func (*Encoding) ValidateString ¶
ValidateString returns the decoded byte count and error that DecodeString would return. On corrupt input, the count covers the successfully decoded prefix and CorruptInputError identifies the original input offset.
On amd64 and arm64, uninterrupted standard and URL input is checked without producing decoded bytes; only the last 64 characters are decoded into stack storage. Large custom alphabets, CR/LF inputs and scalar fallbacks may allocate remaining output.
func (Encoding) WithPadding ¶
WithPadding returns a copy using padding, or NoPadding for unpadded output.