@x-currency/xbase85
v1.0.4
Published
Most Efficient JSON Friendly Byte Encoder ~ JavaScript Base85 Encoding Implementation using Z85's alphabet (no backward slash and quotes)
Downloads
3
Readme
Xbase85: Most Efficient JSON Friendly Byte Encoder
JavaScript Base85 Encoding Implementation using Z85's alphabet (no backward slash and quotes)
Usage
import {encode,decode,decodeStr} from '@x-currency/xbase85';
// .encode accepts both bytes (Uint8Array) and string
console.log( 'encode', encode( Uint8Array.from([0,1,2,3]) ) ); // 009c6
console.log( 'encode' ,encode( 'Hello World!') ); // nm=QNzY&b1A+]nf
// .decode output bytes (Uint8Array)
console.log( 'decode', decode('009c6') ); // Uint8Array(4) [0,1,2,3]
// .decodeStr output string
console.log( 'decodeStr', decodeStr('nm=QNzY&b1A+]nf') ); // Hello World!
Usage in ES5
const { encode, decode, decodeStr } = require('@x-currency/xbase85');
console.log(encode('Hello World!'));
console.log(decode('nm=QNzY&b1A+]nf'));
console.log(decodeStr('nm=QNzY&b1A+]nf'));
Install
npm install @x-currency/xbase85 --save
Note
//
// Note: To enjoy the benefits of Base85 your data MUST have the following properties:
// - data (Uint8Array|String) to be encoded MUST be divideable by 4 (data.length % 4 === 0).
// - data (string) to be decoded MUST be divideable by 5 (data.length % 5 === 0).
//
try {
console.log('encode',encode(Uint8Array.from([1,2,3]))); // must be atleast 4
} catch(err) {
// console.log('expected encode err', String(err) );
// Error: data.length must be divideable by 4 to make base85 encoding possible.
}
try {
console.log('encode',decode('1234')); // must be atleast 5
} catch(err) {
// console.log('expected decode err', String(err) );
// Error: encoded_string.length must be divideable by 5 to make base85 decoding possible.
}