dominode-filestream

streaming HTML5 FileReaders

npm install dominode-filestream
2 downloads in the last week
2 downloads in the last month

dominode FileReader

As suggested by Max Ogden's dominode, this is a streaming implementation of the HTML5 FileReader API. See the dominode readme for more details about why this is cool. If you're still not convinced that streams are awesome, you should probably read this, too.

For more info on how to read local files in the browser checkout this article on HTML5 Rocks and the MDN FileReader docs.

Implementation

  • all FileReader ProgressEvents events trigger 'data' events
  • FilReader error and abort events trigger 'error' on the stream
  • FileStreams support piping to Writable Stream
  • Support for Blob, File, and FileList objects

TODO

  • 'end' events currently aren't ever emitted. This is definitely going to be changing in the future, but I'm looking for feedback on the best way to do this, and still be able to re-use the same FileStream instance multiple times with FileStream#read.
  • Writable Stream support for the local FileSystem APIs. See more on this at HTML5 Rocks.

Example

For a more detailed usage, see example.js

// Pass a FileList or a File object.
var fstream = new FileStream( file );

// Pipe it to any writeable stream - data events are fired on all
// progress and load events from FileReader
fstream.pipe( writeableStream );

// Or, just bind a `data` event handler directly to the stream. The
// handler is passed a FileReader ProgressEvent
fstream.on('data', function(data){
  console.log(data.loaded);
});
npm loves you