Skip to content

eliot-akira/base64-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Base64 Compressor

Compress and encode data as URL-safe base64 string

Screenshot

Why

It can be useful to encode data, such as application state or binary file, into a string that is compressed and safe to use in URL query string or hash, as well as in JSON.

How

For gzip compression and decompression, it uses the Compression Streams API, well-supported by browsers and on server side.

Binary to text encoding is done according to the specification for Base 64 Encoding with URL and Filename Safe Alphabet.

Install

npm install --save base64-compressor

Usage

Encode/decode JSON-serializable JavaScript value

import { encode, decode } from 'base64-compressor'

const object = {
  key: 'value'
}

const base64string = await encode(object)
const decoded =  await decode(base64string)

assert.deepEqual(decoded, object)

Encode/decode binary (array buffer)

import { encodeBinary, decodeBinary } from 'base64-compressor'

const buffer = new ArrayBuffer(8)

const base64string = await encodeBinary(buffer)
const decoded =  await decodeBinary(base64string)

assert.deepEqual(decoded, buffer)