binconv
v0.2.0
Published
Binary converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
Downloads
583
Maintainers
Readme
binconv
Binary converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
Installation
npm i -S binconv
Converters
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()
|
Usage
import * as binconv from 'binconv';
const blob = new Blob(["this is a blob"]);
const readableStream = binconv.blobToReadableStream(blob);
Usage (on-demand import)
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);