
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
A utility that takes a file and generates a collection of SHA1 hashes suitable for use in BitTorrent files.
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.
npm install pieces
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([array])
window.open(
URL.createObjectURL(data)
)
})
}
document.body.appendChild(input)
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())
})
When you start processing larger files, you’ll notice that it takes a while for the callback to be fired (particularly in browsers). To make this more managable, the pieces object emits progress, data, and end events.
Where the implementation differences are denoted with a pipe (ie. browser|server).
var pieces = require('pieces')
var file|path = …
var size = …
pieces(file|path, size)
.on('progress', function(percentage) {
// percentage is a Number between 0 and 100
})
.on('data', function(bytes) {
// bytes is a Uint8Array|Buffer containing a SHA1
})
.on('end', function() {
// And we’re done.
})
FAQs
A utility that takes a file and generates a collection of SHA1 hashes suitable for use in BitTorrent files.
The npm package pieces receives a total of 12 weekly downloads. As such, pieces popularity was classified as not popular.
We found that pieces demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.