...

Package base64x

import "github.com/chenzhuoyu/base64x"
Overview
Index

Overview ▾

type Encoding

An Encoding is a radix 64 encoding/decoding scheme, defined by a 64-character alphabet. The most common encoding is the "base64" encoding defined in RFC 4648 and used in MIME (RFC 2045) and PEM (RFC 1421). RFC 4648 also defines an alternate encoding, which is the standard encoding with - and _ substituted for + and /.

type Encoding int

JSONStdEncoding is the StdEncoding and encoded as JSON string as RFC 8259.

const JSONStdEncoding Encoding = _MODE_JSON

RawStdEncoding is the standard raw, unpadded base64 encoding, as defined in RFC 4648 section 3.2.

This is the same as StdEncoding but omits padding characters.

const RawStdEncoding Encoding = _MODE_RAW

RawURLEncoding is the unpadded alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names.

This is the same as URLEncoding but omits padding characters.

const RawURLEncoding Encoding = _MODE_RAW | _MODE_URL

StdEncoding is the standard base64 encoding, as defined in RFC 4648.

const StdEncoding Encoding = 0

URLEncoding is the alternate base64 encoding defined in RFC 4648. It is typically used in URLs and file names.

const URLEncoding Encoding = _MODE_URL

func (Encoding) Decode

func (self Encoding) Decode(out []byte, src []byte) (int, error)

Decode decodes src using the encoding enc. It writes at most DecodedLen(len(src)) bytes to out and returns the number of bytes written. If src contains invalid base64 data, it will return the number of bytes successfully written and base64.CorruptInputError.

New line characters (\r and \n) are ignored.

If out is not large enough to contain the encoded result, it will panic.

func (Encoding) DecodeString

func (self Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the base64 string s.

func (Encoding) DecodeUnsafe

func (self Encoding) DecodeUnsafe(out *[]byte, src []byte) (int, error)

DecodeUnsafe behaves like Decode, except it does NOT check if out is large enough to contain the decoded result.

It will also update the length of out.

func (Encoding) DecodedLen

func (self Encoding) DecodedLen(n int) int

DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base64-encoded data.

func (Encoding) Encode

func (self Encoding) Encode(out []byte, src []byte)

Encode encodes src using the specified encoding, writing EncodedLen(len(src)) bytes to out.

The encoding pads the output to a multiple of 4 bytes, so Encode is not appropriate for use on individual blocks of a large data stream.

If out is not large enough to contain the encoded result, it will panic.

func (Encoding) EncodeToString

func (self Encoding) EncodeToString(src []byte) string

EncodeToString returns the base64 encoding of src.

func (Encoding) EncodeUnsafe

func (self Encoding) EncodeUnsafe(out *[]byte, src []byte)

EncodeUnsafe behaves like Encode, except it does NOT check if out is large enough to contain the encoded result.

It will also update the length of out.

func (Encoding) EncodedLen

func (self Encoding) EncodedLen(n int) int

EncodedLen returns the length in bytes of the base64 encoding of an input buffer of length n.