# range-slice-stream

> Get slices of a stream

Latest version **3.0.0** (published 2023-12-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install range-slice-stream
pnpm add range-slice-stream
yarn add range-slice-stream
bun add range-slice-stream
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-12-15 |
| First published | 2016-01-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | John Hiesey |
| Maintainers | jhiesey |
| Keywords | stream, slice, substream, range |

## Links

- npm: https://www.npmjs.com/package/range-slice-stream
- Repository: https://github.com/jhiesey/range-slice-stream
- Homepage: https://github.com/jhiesey/range-slice-stream#readme
- Issues: https://github.com/jhiesey/range-slice-stream/issues
- npm.io page: https://npm.io/package/range-slice-stream

## Dependencies (2)

- [@types/node](https://npm.io/package/@types/node.md) ^20.10.4
- [readable-stream](https://npm.io/package/readable-stream.md) ^4.4.2

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

- 3.0.0 (latest) — 2023-12-15
- 2.0.0 — 2018-09-25
- 1.2.0 — 2017-01-14
- 1.1.0 — 2016-02-28
- 1.0.0 — 2016-01-31

## README

# range-slice-stream

Extract a bunch of ranges from a stream to construct a new stream

## Usage

``` js
const RangeSliceStream = require('range-slice-stream')

const slicer = new RangeSliceStream()
slicer.end('abcdefghijklmnop')

const out = slicer.slice([
  { start: 1, end: 3 },
  { start: 6, end: 9 }
])

out.pipe(process.stdout)

// Prints 'bcghi'
```

## API

#### `var slicer = new RangeSliceStream([offset[, opts]])`

Create a new slicer, which is a writable stream.

If an `offset` is provided, it is subtracted from all range offsets. This
makes it more intuitive to use if the incoming data stream itself starts
at an offset into an underlying resource like a file.

`opts` is passed to the underlying writable stream constructor.

#### `var slice = slicer.slice([{start: <s1>, end: <e1>}, {start: <s2>, end: <e2>},...])`

Get a new readable stream that is built by concatenating the data from one
or more byte ranges of the data piped into the slicer. Like the `Buffer.slice()`
method, `start` is inclusive and `end` is exclusive.

`slice()` can be called multiple times to generate multiple streams built from
different sets of ranges. However, all ranges *must* be provided in increasing
order, both within a given call to `slice()` and between calls.

Data between ranges is discarded. Once all ranges specified by `slice()` calls
are satisfied, backpressure will be applied to the incoming stream until the
next desired range is specified by calling `slice()` again.

#### `slicer.satisfied`

Boolean that is true when all `slice()` calls have been satisfied and
backpressure is applied. In addition, the `satisfied` event is emitted
when `slicer.satisfied` becomes true.

## License

MIT

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