basex

package
v1.0.0-40 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 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)

Base58StdEncoding is the standard base58-encoding

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 NewDecoderStrict

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

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

func NewEncoding(encoder string, inBlockLen int) *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 is like DecodeStrict, but first strips out all non-alphabet characters

func (*Encoding) DecodeStrict

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

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

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) DecodeStringStrict

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

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

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 inBlockLen 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) 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