Documentation ¶
Overview ¶
Package zbase32 implements the z-base-32 encoding as specified in http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt
Note that this is NOT RFC 4648, for that see encoding/base32. z-base-32 is a variant that aims to be more human-friendly, and in some circumstances shorter.
Bits ¶
When the amount of input is not a full number of bytes, encoding the data can lead to an unnecessary, non-information-carrying, trailing character in the encoded data. This package provides 'Bits' variants of the functions that can avoid outputting this unnecessary trailing character. For example, encoding a 20-bit message:
EncodeToString([]byte{0x10, 0x11, 0x10}) == "nyety" EncodeBitsToString([]byte{0x10, 0x11, 0x10}, 20) == "nyet"
Decoding such a message requires also using the 'Bits' variant function.
Example ¶
package main import ( "fmt" "github.com/tv42/zbase32" ) func main() { s := zbase32.EncodeToString([]byte{240, 191, 199}) fmt.Println(s) }
Output: 6n9hq
Index ¶
- func Decode(dst, src []byte) (int, error)
- func DecodeBits(dst, src []byte, bits int) (int, error)
- func DecodeBitsString(s string, bits int) ([]byte, error)
- func DecodeString(s string) ([]byte, error)
- func DecodedLen(n int) int
- func Encode(dst, src []byte) int
- func EncodeBits(dst, src []byte, bits int) int
- func EncodeBitsToString(src []byte, bits int) string
- func EncodeToString(src []byte) string
- func EncodedLen(n int) int
- type CorruptInputError
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode decodes z-base-32 encoded data from src. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written.
If src contains invalid z-base-32 data, it will return the number of bytes successfully written and CorruptInputError.
func DecodeBits ¶
DecodeBits decodes the specified number of bits of z-base-32 encoded data from src. It writes at most DecodedLen(len(src)) bytes to dst and returns the number of bytes written.
If src contains invalid z-base-32 data, it will return the number of bytes successfully written and CorruptInputError.
func DecodeBitsString ¶
DecodeBitsString returns the bytes represented by the z-base-32 string s containing the specified number of bits.
func DecodeString ¶
DecodeString returns the bytes represented by the z-base-32 string s.
func DecodedLen ¶
DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of z-base-32-encoded data.
func Encode ¶
Encode encodes src. It writes at most EncodedLen(len(src)) bytes to dst and returns the number of bytes written.
Encode is not appropriate for use on individual blocks of a large data stream.
func EncodeBits ¶
EncodeBits encodes the specified number of bits of src. It writes at most EncodedLen(len(src)) bytes to dst and returns the number of bytes written.
EncodeBits is not appropriate for use on individual blocks of a large data stream.
Panics if bits is greater than number of bits in src.
func EncodeBitsToString ¶
EncodeBitsToString returns the z-base-32 encoding of the specified number of bits of src.
Panics if bits is greater than number of bits in src.
func EncodeToString ¶
EncodeToString returns the z-base-32 encoding of src.
func EncodedLen ¶
EncodedLen returns the maximum length in bytes of the z-base-32 encoding of an input buffer of length n.
Types ¶
type CorruptInputError ¶
type CorruptInputError int64
CorruptInputError means that the byte at this offset was not a valid z-base-32 encoding byte.
func (CorruptInputError) Error ¶
func (e CorruptInputError) Error() string
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
zbase32-decode
Command zbase32-decode decodes zbase32 from arguments or lines of stdin.
|
Command zbase32-decode decodes zbase32 from arguments or lines of stdin. |
zbase32-encode
Command zbase32-encode encodes its standard input as zbase32.
|
Command zbase32-encode encodes its standard input as zbase32. |