https://github.com/nwtgck/binconv-npm
Converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
https://github.com/nwtgck/binconv-npm
arraybuffer base64 binary blob conversion converter javascript readablestream typescript uint8array
Last synced: about 1 month ago
JSON representation
Converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
- Host: GitHub
- URL: https://github.com/nwtgck/binconv-npm
- Owner: nwtgck
- License: mit
- Created: 2019-09-29T00:19:58.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2024-04-08T07:57:28.000Z (about 1 year ago)
- Last Synced: 2025-04-16T13:39:09.364Z (2 months ago)
- Topics: arraybuffer, base64, binary, blob, conversion, converter, javascript, readablestream, typescript, uint8array
- Language: TypeScript
- Homepage:
- Size: 886 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# binconv
[](https://www.npmjs.com/package/binconv) [](https://circleci.com/gh/nwtgck/binconv-npm)Binary converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
## Installation
```bash
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()` |## Other binary utilities
```ts
function mergeUint8Array(a: Uint8Array, b: Uint8Array): Uint8Array;
function mergeAllUint8Arrays(arrays: ReadonlyArray): Uint8Array;
```## Usage
```ts
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.
```ts
import {blobToReadableStream} from 'binconv/dist/src/blobToReadableStream';const blob = new Blob(["this is a blob"]);
const readableStream = blobToReadableStream(blob);
```