Skip to content

Read an HTML5 File object (from e.g. HTML5 drag and drops) as a pull stream source.

License

Notifications You must be signed in to change notification settings

tableflip/pull-file-reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pull-file-reader dependencies Status

Given an HTML5 File object (from e.g. HTML5 drag and drops), turn it into a pull stream source.

Heavily based on filereader-stream by @maxogden.

install

Use it with npm & browserify

npm install pull-file-reader

example

var drop = require('drag-and-drop-files')
var pull = require('pull-stream')
var fileReader = require('pull-file-reader')

drop(document.body, function (files) {
  var first = files[0]
  pull(
    fileReader(first),
    pull.collect(function (err, buffs) {
      var contents = Buffer.concat(buffs)
      // contents is the contents of the entire file
    })
  )
})

usage

var fileReader = require('pull-file-reader')
var source = fileReader(file, [options])

fileReader is a pull stream source.

options:

  • chunkSize - default 1024 * 1024 (1MB) - How many bytes will be read at a time
  • offset - default 0 - Where in the file to start reading

run the tests

npm install
npm test

then open your browser to the address provided, open your JS console, and drag and drop files onto the page until the test suite passes/fails


A (╯°□°)╯︵TABLEFLIP side project.

js-standard-style

About

Read an HTML5 File object (from e.g. HTML5 drag and drops) as a pull stream source.

Resources

License

Stars

Watchers

Forks

Packages

No packages published