Documentation ¶
Index ¶
- Variables
- func NewDecoder(enc *Encoding, r io.Reader) io.Reader
- func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
- type CorruptInputError
- type 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) IsValidByte(b byte) bool
- func (enc *Encoding) IsValidEncodingLength(n int) bool
Constants ¶
This section is empty.
Variables ¶
var Base58StdEncoding = NewEncoding(base58EncodeStd, 19, b58skipChars)
Base58StdEncoding is the standard base58-encoding. Foreign characters are ignored as long as they're from the blessed set.
var Base58StdEncodingStrict = NewEncoding(base58EncodeStd, 19, "")
Base58StdEncoding is the standard base58-encoding, with Strict mode enforcing no foreign characters
var Base62StdEncoding = NewEncoding(base62EncodeStd, 32, "\t\n\r >")
Base62StdEncoding is the standard 62-encoding, with a 32-byte input block and, a 43-byte output block. Foreign chracters are ignored
var Base62StdEncodingStrict = NewEncoding(base62EncodeStd, 32, "")
Base62StdEncoding is the standard 62-encoding, with a 32-byte input block and, a 43-byte output block. Strict mode is on, so no foreign characters.
var ErrInvalidEncodingLength = errors.New("invalid encoding length; either truncated or has trailing garbage")
ErrInvalidEncodingLength is returned when a non-minimal encoding length is found
Functions ¶
func NewDecoder ¶
NewDecoder constructs a new baseX stream decoder.
func NewEncoder ¶
func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
NewEncoder returns a new baseX stream encoder. Data written to the returned writer will be encoded using enc and then written to w. Encodings operate in enc.baseXBlockLen-byte blocks; when finished writing, the caller must Close the returned encoder to flush any partially written blocks.
Types ¶
type CorruptInputError ¶
type CorruptInputError int
CorruptInputError is returned when Decode() finds a non-alphabet character
func (CorruptInputError) Error ¶
func (e CorruptInputError) Error() string
Error fits the error interface
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
Encoding is a radix X encoding/decoding scheme, defined by X-length character alphabet.
func NewEncoding ¶
NewEncoding returns a new Encoding defined by the given alphabet, which must a x-byte string. No padding options are currently allowed. inBlock is the size of input blocks to consider.
For base 58, we recommend 19-byte input blocks, which encode to 26-byte output blocks with only .3 bits wasted per block. The name of the game is to find a good rational approximation of 8/log2(58), and 26/19 is pretty good!
func (*Encoding) Decode ¶
Decode decodes src using the encoding enc. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written. If src contains invalid baseX data, it will return the number of bytes successfully written and CorruptInputError. It can also return an ErrInvalidEncodingLength error if there is a non-standard number of bytes in this encoding
func (*Encoding) DecodeString ¶
DecodeString returns the bytes represented by the baseX string s. It uses the liberal decoding strategy, ignoring any non-baseX-characters
func (*Encoding) DecodedLen ¶
DecodedLen returns the length in bytes of the baseX decoding of an input buffer of length n
func (*Encoding) Encode ¶
Encode encodes src using the encoding enc, writing EncodedLen(len(src)) bytes to dst.
The encoding aligns the input along base256BlockLen boundaries. so Encode is not appropriate for use on individual blocks of a large data stream. Use NewEncoder() instead.
func (*Encoding) EncodeToString ¶
EncodeToString returns the base64 encoding of src.
func (*Encoding) EncodedLen ¶
EncodedLen returns the length in bytes of the baseX encoding of an input buffer of length n
func (*Encoding) IsValidByte ¶
IsValidByte returns true if the given byte is valid in this decoding. Can be either from the main alphabet or the skip alphabet to be considered valid.
func (*Encoding) IsValidEncodingLength ¶
IsValidEncodingLength returns true if this block has a valid encoding length. An encoding length is invalid if a short encoding would have sufficed.