项目作者: DistributedWeb

项目描述 :
dDatabase byte stream
高级语言: JavaScript
项目地址: git://github.com/DistributedWeb/ddatabase-byte-stream.git
创建时间: 2020-08-21T13:06:34Z
项目社区:https://github.com/DistributedWeb/ddatabase-byte-stream

开源协议:MIT License

下载


ddatabase-byte-stream

Build Status

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.

Usage

The following example will return a byte stream of the entire input feed.

  1. const ram = require('random-access-memory')
  2. const ddatabase = require('ddatabase')
  3. const createByteStream = require('ddatabase-byte-stream')
  4. let core = ddatabase(ram)
  5. let stream = createByteStream({
  6. feed: core
  7. })

API

stream = createStream([options])

Creates a new byte stream.

If specified, options can include:

  1. {
  2. feed: core, // A ddatabase.
  3. byteOffset: 0, // Starting offset in bytes from the start of the feed.
  4. byteLength: 10, // The number of bytes to read.
  5. blockOffset: 0, // An optional starting block heuristic (optimization).
  6. blockLength: 10 // An optional block length that should contain the entire range (optimization).
  7. }

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