Socket
Book a DemoInstallSign in
Socket

fs-readstream-progress

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-readstream-progress

fs-readstream-progress

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

fs-readstream-progress

fs.createReadStream that emits progress events. Also works with hyperdrive.

What problem does this solve?

Track the progress of readStreams for Node fs or hyperdrive archives.

Install

npm install fs-readstream-progress

Usage

Use it like fs.createReadStream, except that:

  • it also emits progress events
  • you can pass an alternative fs
  • it has a convenient .drain() method

API:

var getwithprogress = require('fs-readstream-progress')

var stream = getwithprogress(filename, opts)

Progress events

Example:

var progress = require('fs-readstream-progress')

progress('somefile')
  .on('progress', function (data) { console.log('progress:', data) })
  .on('data', function(data) {})
  .on('end', function() { console.log('done') })

Each progress event looks like:

{
  done: 16, // integer, number of bytes streamed so far
  total: 256, // integer, total number of bytes
  progress: 0.0625 // float, proportion of the data streamed
}

When all the data have been streamed, the stream will emit end, just like fs.createReadStream.

Different fs

To use a different fs implementation (e.g. a hyperdrive archive), just pass

var hyperdrive = require('hyperdrive')
var getwithprogress = require('fs-readstream-progress')

var archive = hyperdrive('.')
var stream = getwithprogress('somefile', { fs: archive })

.drain()

Drains the stream, pulling all data through without keeping it in memory.

This is useful if you just want to track a download from a hyperdrive archive.

License

To the extent possible by law, we transfer any rights we have in this code to the public domain. Specifically, we do so using the CC0 1.0 Universal Public Domain Dedication.

You can do whatever you want with this code. No need to credit us, link to us, include any license, or anything else. But if you want to do those things, you're free to do that too.

FAQs

Package last updated on 30 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts