base91

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: BSD-3-Clause Imports: 2 Imported by: 3

README

base91

Go Report Card GoDoc

A Go implementation of base91 encoding with an interface as close as possible to that of the standard library's encoding/base64 (https://golang.org/pkg/encoding/base64).

The encoding/base64 Encoding type and this package's Encoding type both satisfy this interface:

type BaseNEncoding interface {
  Decode(dst, src []byte) (int, error)
  DecodeString(s string) ([]byte, error)
  DecodedLen(n int) int
  
  // The signature of Encode is different in this package and
  // encoding/base64: this package returns the number of bytes
  // written because the encoded length cannot be known from just
  // the number of bytes to encode, whereas it can with base64.
  // Encode(dst, src []byte)
  
  EncodeToString(src []byte) string
  EncodedLen(n int) int
}

Documentation

Overview

Package base91 implements base91 encoding.

Index

Constants

This section is empty.

Variables

View Source
var StdEncoding = NewEncoding(encodeStd)

StdEncoding is the standard base91 encoding (that is, the one specified at http://base91.sourceforge.net). Of the 95 printable ASCII characters, the following four are omitted: space (0x20), apostrophe (0x27), hyphen (0x2d), and backslash (0x5c).

Functions

This section is empty.

Types

type CorruptInputError

type CorruptInputError int64

A CorruptInputError is returned if invalid base91 data is encountered during decoding.

func (CorruptInputError) Error

func (e CorruptInputError) Error() string

type Encoding

type Encoding struct {
	// contains filtered or unexported fields
}

An Encoding is a base 91 encoding/decoding scheme defined by a 91-character alphabet.

func NewEncoding

func NewEncoding(encoder string) *Encoding

NewEncoding returns a new Encoding defined by the given alphabet, which must be a 91-byte string that does not contain CR or LF ('\r', '\n').

func (*Encoding) Decode

func (enc *Encoding) Decode(dst, src []byte) (int, 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 base91 data, it will return the number of bytes successfully written and CorruptInputError.

func (*Encoding) DecodeString

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

DecodeString returns the bytes represented by the base91 string s.

func (*Encoding) DecodedLen

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

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

func (*Encoding) Encode

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

Encode encodes src using the encoding enc, writing bytes to dst. It returns the number of bytes written, because the exact output size cannot be known before encoding takes place. EncodedLen(len(src)) may be used to determine an upper bound on the output size when allocating a dst slice.

func (*Encoding) EncodeToString

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

EncodeToString returns the base91 encoding of src.

func (*Encoding) EncodedLen

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

EncodedLen returns an upper bound on the length in bytes of the base91 encoding of an input buffer of length n. The true encoded length may be shorter.

Jump to

Keyboard shortcuts

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