package base64
import "github.com/segmentio/asm/base64"
Index ¶
- Constants
- Variables
- type Encoding
- func NewEncoding(encoder string) *Encoding
- func (enc *Encoding) Decode(dst, src []byte) (n int, err error)
- func (enc *Encoding) DecodeString(s string) ([]byte, error)
- func (enc *Encoding) DecodedLen(n int) int
- func (enc *Encoding) Encode(dst, src []byte)
- func (enc *Encoding) EncodeToString(src []byte) string
- func (enc *Encoding) EncodedLen(n int) int
- func (enc Encoding) Strict() *Encoding
- func (enc Encoding) WithPadding(padding rune) *Encoding
Constants ¶
Variables ¶
var RawStdEncoding = StdEncoding.WithPadding(NoPadding)
RawStdEncoding is the standard unpadded base64 encoding defined in RFC 4648 section 3.2. This is the same as StdEncoding but omits padding characters.
var RawURLEncoding = URLEncoding.WithPadding(NoPadding)
RawURLEncoding is the unpadded alternate base64 encoding defined in RFC 4648. This is the same as URLEncoding but omits padding characters.
var StdEncoding = NewEncoding(encodeStd)
StdEncoding is the standard base64 encoding, as defined in RFC 4648.
var URLEncoding = NewEncoding(encodeURL)
URLEncoding is the alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names.
Types ¶
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
An Encoding is a radix 64 encoding/decoding scheme, defined by a 64-character alphabet.
func NewEncoding ¶
NewEncoding returns a new padded Encoding defined by the given alphabet, which must be a 64-byte string that does not contain the padding character or CR / LF ('\r', '\n'). Unlike the standard library, the encoding alphabet cannot be abitrary, and it must follow one of the know standard encoding variants.
Required alphabet values:
- [0,26): characters 'A'..'Z'
- [26,52): characters 'a'..'z'
- [52,62): characters '0'..'9'
Flexible alphabet value options:
- RFC 4648, RFC 1421, RFC 2045, RFC 2152, RFC 4880: '+' and '/'
- RFC 4648 URI: '-' and '_'
- RFC 3501: '+' and ','
The resulting Encoding uses the default padding character ('='), which may be changed or disabled via WithPadding. The padding characters is urestricted, but it must be a character outside of the encoder alphabet.
func (*Encoding) Decode ¶
Decode decodes src using the defined encoding alphabet. This will write DecodedLen(len(src)) bytes to dst and return the number of bytes written.
func (*Encoding) DecodeString ¶
DecodeString decodes the base64 encoded string s, returns the decoded value as bytes.
func (*Encoding) DecodedLen ¶
DecodedLen calculates the decoded byte length for a base64-encoded message of length n.
func (*Encoding) Encode ¶
Encode encodes src using the defined encoding alphabet. This will write EncodedLen(len(src)) bytes to dst.
func (*Encoding) EncodeToString ¶
Encode encodes src using the encoding enc, writing EncodedLen(len(src)) bytes to dst.
func (*Encoding) EncodedLen ¶
EncodedLen calculates the base64-encoded byte length for a message of length n.
func (Encoding) Strict ¶
Strict creates a duplicate encoding updated with strict decoding enabled. This requires that trailing padding bits are zero.
func (Encoding) WithPadding ¶
WithPadding creates a duplicate Encoding updated with a specified padding character, or NoPadding to disable padding. The padding character must not be contained in the encoding alphabet, must not be '\r' or '\n', and must be no greater than '\xFF'.
Source Files ¶
base64.go base64_amd64.go decode_amd64.go encode_amd64.go
- Version
- v1.1.1
- Published
- Nov 13, 2021
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 2 hours ago –
Tools for package owners.