buffer-to-base64
v0.1.6
Published
A base64 encoder/decoder with gzip or deflate abilities
Downloads
103
Readme
buffer-to-base64
Social Media Photo by Belinda Fewings on Unsplash
A base64 encoder/decoder with gzip
or deflate
abilities.
import { encode, decode, stream } from 'buffer-to-base64';
// return a base64 string after compression
const packed = await encode(buffer);
// return an ArrayBuffer after decompression
const original = await decode(packed);
// initialize a WebAssembly module streaming
const response = stream(packed, { type: 'application/wasm' });
// eventually returns the ArrayBuffer too (fast decoding)
const arrayBuffer = await (await response).arrayBuffer();
// `arrayBuffer` is the same as `original`
This module goal is to simplify the embedding of WASM or other blobs within code as base64
that can return the original array without bloating space on the file.