An abstract-random-access compliant module for reading files in the browser using the FileReader API and browserify.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 823ac60 May 13, 2018
Permalink
Failed to load latest commit information.
.gitignore first commit Aug 9, 2016
.travis.yml drop old versions May 13, 2018
LICENSE first commit Aug 9, 2016
README.md update badge May 13, 2018
example.js upgrade to use random-access-storage May 13, 2018
index.js upgrade to use random-access-storage May 13, 2018
package.json bump standard May 13, 2018

README.md

random-access-file-reader

A random-access-storage compliant module for reading files in the browser using the FileReader API and browserify.

build status

npm install random-access-file-reader

Usage

var raf = require('random-access-file-readers')
var drop = require('drag-and-drop-files')

drop(document.body, function (files) {
  var file = raf(files[0])

  file.read(0, 1000, function (err, data) {
    console.log('first 1000 bytes:', err, data)
  })
})

You can use this to read files into hyperdrive as well

var hyperdrive = require('hyperdrive')
var drive = hyperdrive(db)

var files = {}
var archive = drive.createArchive({
  file: function (name) {
    return raf(files[name])
  }
})

drop(document.body, function (files) {
  files[files[0].name] = files[0]
  // will index the file using hyperdrive without reading the entire file into ram
  archive.append(files[0].name)
})

API

var file = raf(browserFile)

Create a new instance. Accepts a browser file object. The file object has an random-access-storage compliant API interface. Note that it is readonly so writes will fail.

License

MIT