n85 0.1.0

N85 (Ascii85 variant) encoder & decoder
Documentation
  • Coverage
  • 100%
    15 out of 15 items documented1 out of 9 items with examples
  • Size
  • Source code size: 10.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.53 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Demindiro

N85 encoder & decoder.

docs.rs crates.io crates.io

N85 is a binary-to-ASCII encoding based on Ascii85 but more suitable for use as strings (i.e. excludes \, ' and ") and with a simpler implementation than the other variants.

Every 4 bytes is mapped to 5 characters, adding ~25% of storage overhead. For comparison, base64 maps every 3 bytes to 4 characters, adding ~33% overhead.

Example

let s = "Hello, world!";

let enc = n85::encode_string(s.as_ref());
assert_eq!(&enc, "Yb(qJ[NH@N0AO?HI(");

let dec = n85::decode_vec(enc.as_ref()).unwrap();
assert_eq!(&dec, s.as_bytes());

Specification

An arbitrary byte string is split into chunks for 32-bit little endian integers. The last chunk is padded with zeroes.

Every integer is 5 times divided by 85, giving 5 remainders. 40 (() is added to each remainder. If the result is equal or greater to 92 (\), 1 is added.

If the last chunk is 1, 2, 3 or 4 byte large, 2, 3, 4 or 5 characters are used for encoding respectively.