Skip to content

WebReflection/buffer-to-base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buffer-to-base64

build status Coverage Status

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.