# async-readable

> Async read for NodeJS.ReadableStream

Latest version **0.4.2** (published 2020-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-readable
pnpm add async-readable
yarn add async-readable
bun add async-readable
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2020-09-08 |
| First published | 2019-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | imcotton |
| Keywords | async, readable, stream |

## Links

- npm: https://www.npmjs.com/package/async-readable
- Repository: https://github.com/imcotton/async-readable
- Homepage: https://github.com/imcotton/async-readable#readme
- Issues: https://github.com/imcotton/async-readable/issues
- npm.io page: https://npm.io/package/async-readable

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.4.2 (latest) — 2020-09-08
- 0.4.1 — 2020-09-07
- 0.4.0 — 2020-08-20
- 0.3.0 — 2020-08-19
- 0.2.3 — 2020-05-10
- 0.2.2 — 2020-01-13
- 0.2.1 — 2019-08-06
- 0.2.0 — 2019-08-05
- 0.2.0-3 — 2019-08-05
- 0.2.0-2 — 2019-08-05
- 0.2.0-1 — 2019-08-04
- 0.2.0-0 — 2019-08-04
- 0.1.5 — 2019-07-26
- 0.1.4 — 2019-07-18
- 0.1.4-0 — 2019-07-18
- … 3 more at https://npm.io/package/async-readable/versions

## README

async-readable
==============

[![npm version](https://badgen.net/npm/v/async-readable)](https://www.npmjs.com/package/async-readable)
[![actions](https://github.com/imcotton/async-readable/workflows/Check/badge.svg)](https://github.com/imcotton/async-readable/actions)
[![codecov](https://codecov.io/gh/imcotton/async-readable/branch/master/graph/badge.svg)](https://codecov.io/gh/imcotton/async-readable)

Utils for reading streams in paused mode (pull stream).





How to Use
----------

### Basic

```javascript
const { createReadStream } = require('fs');
const { asyncReadable } = require('async-readable');

async function parse_GIF_size (path) {

    const { read } = asyncReadable(createReadStream(path));

    const [ G, I, F ] = await read(3);
    const [ EIGHT, SEVEN_OR_NINE, A ] = await read(3);

    const width = (await read(2)).readUInt16LE(0);
    const height = (await read(2)).readUInt16LE(0);

    return { width, height };

}

parse_GIF_size('./sample.gif').then(console.log, console.error);
```





### Advanced

_assuming to have_

```javascript
const { connect } = require('net');

const socket = connect({ host: 'localhost', port: 8080 });

async function* process ({ read }) {

    while (true) {
        const head = await read(2);
        const size = head.readUInt16LE(0);
        yield read(size);
    }

}
```

_hence_

```javascript
const { toAsyncIterable } = require('async-readable');

const unpack = toAsyncIterable(process);

async function run () {

    for await (const frame of unpack(socket)) {
        // ...
    }

}
```

_or_

```javascript
const { toReadableStream } = require('async-readable');

const unpack = toReadableStream(process);

function run () {

    const stream = unpack(socket);

    stream.on('data', frame => {
        // ...
    });

}
```





License
-------

the MIT

---
_Source: https://npm.io/package/async-readable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
