Binary converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
npm i -S binconv
Here are avaiable converters.
Naming rule: A
→ B
should be aToB()
.
conversion | function |
---|---|
Base64 → Uint8Array |
base64ToUint8Array() |
Blob → ArrayBuffer |
blobToArrayBuffer() |
Blob → ReadableStream |
blobToReadableStream() |
Blob → Uint8Array |
blobToUint8Array() |
ReadableStream → Blob |
readableStreamToBlob() |
ReadableStream → Uint8Array |
readableStreamToUint8Array() |
string → Uint8Array |
stringToUint8Array() |
string → ArrayBuffer |
stringArrayBuffer() |
Uint8Array → ArrayBuffer |
uint8ArrayToArrayBuffer() |
Uint8Array → Base64 |
uint8ArrayToBase64() |
Uint8Array → Blob |
uint8ArrayToBlob() |
Uint8Array → hex string |
uint8ArrayToHexString() |
Uint8Array → ReadableStream |
uint8ArrayToReadableStream() |
Uint8Array → string |
uint8ArrayToString() |
function mergeUint8Array(a: Uint8Array, b: Uint8Array): Uint8Array;
function mergeAllUint8Arrays(arrays: ReadonlyArray<Uint8Array>): Uint8Array;
import * as binconv from 'binconv';
const blob = new Blob(["this is a blob"]);
const readableStream = binconv.blobToReadableStream(blob);
You can import only specific conversion to reduce file size.
import {blobToReadableStream} from 'binconv/dist/src/blobToReadableStream';
const blob = new Blob(["this is a blob"]);
const readableStream = blobToReadableStream(blob);