0.2.0 • Published 12 years ago

pieces v0.2.0

Weekly downloads
3
License
-
Repository
github
Last release
12 years ago

pieces

pieces is a utility that takes a file (browser) or file path (node) and a piece length, and generates a collection of SHA1 hashes that can be used when creating BitTorrent files.

Build status

Browser support

Install

npm install pieces

Example

browser(ify)

var pieces = require('pieces')

var size = Math.pow(2, 14) // 16kb

// Typically you’ll get the File object from
// an input[type=file], but you you could also
// just create your own Blob.

var input = document.createElement('input')
input.type = 'file'
input.onchange = function(e) {
  var file = e.target.files[0]
  pieces(file, size, function(error, array) {
    // Returns a Uint8Array of binary data
    var data = new Blob([pieces])
    window.open(
      URL.createObjectURL(data)
    )
  })
}

document.body.appendChild(input)

node

var pieces = require('pieces')

var path = '/path/to/file'
var size = Math.pow(2, 18) // 256kb

// You should probably make sure the path
// exists before running pieces

pieces(path, size, function(error, buffer) {
  // Returns a Buffer of binary data
  console.log(buffer.toString())
})

License

MIT

0.2.0

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.6

12 years ago

0.0.5

12 years ago

0.0.1

12 years ago

0.0.0

12 years ago