basex

package
v1.0.6-0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2015 License: BSD-3-Clause, BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Base58StdEncoding = NewEncoding(base58EncodeStd, 19, skipChars)

Base58StdEncoding is the standard base58-encoding. Foreign characters are ignored as long as they're from the blessed set.

View Source
var Base58StdEncodingStrict = NewEncoding(base58EncodeStd, 19, "")

Base58StdEncoding is the standard base58-encoding, with Strict mode enforcing no foreign characters

View Source
var Base62StdEncoding = NewEncoding(base62EncodeStd, 32, skipChars)

Base62StdEncoding is the standard 62-encoding, with a 32-byte input block and, a 43-byte output block. Foreign chracters are ignored

View Source
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.

View Source
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

func NewDecoder(enc *Encoding, r io.Reader) io.Reader

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

func NewEncoding(encoder string, base256BlockLen int, skipBytes string) *Encoding

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

func (enc *Encoding) Decode(dst, src []byte) (n int, err error)

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

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

DecodeString returns the bytes represented by the baseX string s. It uses the liberal decoding strategy, ignoring any non-baseX-characters

func (*Encoding) DecodedLen

func (enc *Encoding) DecodedLen(n int) int

DecodedLen returns the length in bytes of the baseX decoding of an input buffer of length n

func (*Encoding) Encode

func (enc *Encoding) Encode(dst, src []byte)

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

func (enc *Encoding) EncodeToString(src []byte) string

EncodeToString returns the base64 encoding of src.

func (*Encoding) EncodedLen

func (enc *Encoding) EncodedLen(n int) int

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

func (*Encoding) IsValidByte

func (enc *Encoding) IsValidByte(b byte) bool

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

func (enc *Encoding) IsValidEncodingLength(n int) bool

IsValidEncodingLength returns true if this block has a valid encoding length. An encoding length is invalid if a short encoding would have sufficed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL