Documentation ¶
Index ¶
- Variables
- func NewDecoder(enc *Encoding, r io.Reader) io.Reader
- func NewDecoderStrict(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) DecodeStrict(dst, src []byte) (n int, err error)
- func (enc *Encoding) DecodeString(s string) ([]byte, error)
- func (enc *Encoding) DecodeStringStrict(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) IsValidEncodingLength(n int) bool
Constants ¶
This section is empty.
Variables ¶
var Base58StdEncoding = NewEncoding(base58EncodeStd, 19)
Base58StdEncoding is the standard base58-encoding
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 NewDecoderStrict ¶
NewDecoderStrict constructs a new baseX stream decoder, but will return an error on any non-base-X character input
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.outBlockLen-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
}
An 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 is like DecodeStrict, but first strips out all non-alphabet characters
func (*Encoding) DecodeStrict ¶
DecodeStrict 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) DecodeStringStrict ¶
DecodeStringStrict returns the bytes represented by the baseX string s. It uses the strict decoding strategy, not allowing 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 inBlockLen 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) IsValidEncodingLength ¶
IsValidEncodingLength returns true if this block has a valid encoding length. An encoding length is invalid if a short encoding would have sufficed.