# @vates/read-chunk

> Read a chunk of a Node stream

Latest version **1.2.1** (published 2025-08-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install @vates/read-chunk
pnpm add @vates/read-chunk
yarn add @vates/read-chunk
bun add @vates/read-chunk
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2025-08-27 |
| First published | 2020-05-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.10 |
| Dependencies | 1 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 987 |
| Author | Vates SAS |
| Maintainers | florent.beauchamp, mathieura, julien-f, marsaud, olivierlambert, pdonias, tgoettelmann, enishowk, b-nollet, mlssfrncjrg, arnogues, joris-k, nathanael-h, olivier.f, pierre.brunet289 |
| Keywords | async, chunk, data, node, promise, read, stream |

## Links

- npm: https://www.npmjs.com/package/@vates/read-chunk
- Repository: https://github.com/vatesfr/xen-orchestra
- Homepage: https://github.com/vatesfr/xen-orchestra/tree/master/@vates/read-chunk
- Issues: https://github.com/vatesfr/xen-orchestra/issues
- npm.io page: https://npm.io/package/@vates/read-chunk

## Dependencies (1)

- [isutf8](https://npm.io/package/isutf8.md) ^4.0.0

## 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

- 1.2.1 (latest) — 2025-08-27
- 1.2.0 — 2023-07-28
- 1.1.1 — 2023-04-26
- 1.1.0 — 2023-03-31
- 1.0.1 — 2022-10-27
- 1.0.0 — 2022-06-29
- 0.1.2 — 2021-04-07
- 0.1.1 — 2020-05-29
- 0.1.0 — 2020-05-28

## README

<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->

# @vates/read-chunk

[![Package Version](https://badgen.net/npm/v/@vates/read-chunk)](https://npmjs.org/package/@vates/read-chunk) ![License](https://badgen.net/npm/license/@vates/read-chunk) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/read-chunk)](https://bundlephobia.com/result?p=@vates/read-chunk) [![Node compatibility](https://badgen.net/npm/node/@vates/read-chunk)](https://npmjs.org/package/@vates/read-chunk)

> Read a chunk of a Node stream

## Install

Installation of the [npm package](https://npmjs.org/package/@vates/read-chunk):

```sh
npm install --save @vates/read-chunk
```

## Usage

### `readChunk(stream, [size])`

- returns the next available chunk of data
- like `stream.read()`, a number of bytes can be specified
- returns with less data than expected if stream has ended
- returns `null` if the stream has ended and no data has been read

```js
import { readChunk } from '@vates/read-chunk'
;(async () => {
  let chunk
  while ((chunk = await readChunk(stream, 1024)) !== null) {
    // do something with chunk
  }
})()
```

### `readChunkStrict(stream, [size])`

Similar behavior to `readChunk` but throws if the stream ended before the requested data could be read.

```js
import { readChunkStrict } from '@vates/read-chunk'

const chunk = await readChunkStrict(stream, 1024)
```

### `skip(stream, size)`

Skips a given number of bytes from a stream.

Returns the number of bytes actually skipped, which may be less than the requested size if the stream has ended.

```js
import { skip } from '@vates/read-chunk'

const bytesSkipped = await skip(stream, 2 * 1024 * 1024 * 1024)
```

### `skipStrict(stream, size)`

Skips a given number of bytes from a stream and throws if the stream ended before enough stream has been skipped.

```js
import { skipStrict } from '@vates/read-chunk'

await skipStrict(stream, 2 * 1024 * 1024 * 1024)
```

## Contributions

Contributions are _very_ welcomed, either on the documentation or on
the code.

You may:

- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
  you've encountered;
- fork and create a pull request.

## License

[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)

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