# @ddatabase/byte-stream

> A Readable stream wrapper around DDatabase that supports reading byte ranges.

Latest version **1.0.2** (published 2021-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ddatabase/byte-stream
pnpm add @ddatabase/byte-stream
yarn add @ddatabase/byte-stream
bun add @ddatabase/byte-stream
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-03-26 |
| First published | 2021-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | PeepsLabs |
| Maintainers | dwebprotocol |
| Keywords | ddatabase, dweb, ddrive |

## Links

- npm: https://www.npmjs.com/package/@ddatabase/byte-stream
- Repository: https://github.com/dwebprotocol/ddatabase-byte-stream
- Homepage: https://dwebx.org
- Issues: https://github.com/dwebprotocol/ddatabase-byte-stream/issues
- npm.io page: https://npm.io/package/@ddatabase/byte-stream

## Dependencies (1)

- [readable-stream](https://npm.io/package/readable-stream.md) ^3.1.1

## Recent versions

- 1.0.2 (latest) — 2021-03-26
- 1.0.1 — 2021-03-25
- 1.0.0 — 2021-03-05

## README

# @ddatabase/byte-stream


A Readable stream wrapper around dDatabase that supports reading byte ranges.

When provided with optional start/end block heuristics, this module will efficiently sync only those blocks which contain the specified range.

Supports asynchronously specifying stream options, as well as the input feed, to remove the need for additional stream management modules like `duplexify`.

Most of the code has been extracted from [dDrive](https://github.com/dwebprotocol/ddrive).

## Usage
The following example will return a byte stream of the entire input feed.
```js
const ram = require('random-access-memory')
const ddatabase = require('ddatabase')
const createByteStream = require('@ddatabase/byte-stream')

let base = ddatabase(ram)
let stream = createByteStream({
  feed: base
})
```

## API
### `stream = createStream([options])`
Creates a new byte stream.

If specified, options can include:
```js
{
  feed: base, // A dDatabase.
  byteOffset: 0, // Starting offset in bytes from the start of the feed.
  byteLength: 10, // The number of bytes to read.
  blockOffset: 0, // An optional starting block heuristic (optimization).
  blockLength: 10 // An optional block length that should contain the entire range (optimization).
}
```

### `stream.start([options])`
Starts downloading and streaming according to the specified options.

Options are the same as in `createStream`. If a `feed` was specified in the stream constructor, then one should *not* provide
another stream in the `start` options.

## License
MIT

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