Socket
Socket
Sign inDemoInstall

piece-length

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piece-length - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

test.js

13

index.js

@@ -1,10 +0,7 @@

var closest = require('closest-to')
var kB = Math.pow(2, 10)
module.exports = length
// Create a range from 16kb–4mb
var p = 13, range = []
while (p++ < 22) range.push(Math.pow(2, p))
module.exports = function (bytes) {
return closest(bytes / kB, range)
function length (bytes, p) {
bytes /= 1024
for (p = 20; 13 < p && bytes < 2 << p; p--);
return 2 << p + (bytes >= ((2 << p) + (2 << p + 1)) / 2)
}
{
"name": "piece-length",
"version": "1.0.0",
"description": "Finds the optimal piece length for a given number of bytes.",
"author": ["Michael Rhodes", "Jimmy Wärting <jimmy@warting.se>"],
"version": "1.0.1",
"main": "index.js",
"directories": {
"test": "test"
},
"dependencies": {
"closest-to": "~2.0.0"
},
"license": "MIT",
"devDependencies": {
"tape": "~2.0.0"
"tape": "^4.11.0"
},
"scripts": {
"test": "tape test/*.js"
},
"testling": {
"files": "test/*.js",
"browsers": {
"ie": [7, 8, 9, 10],
"chrome": [25],
"firefox": [4, 19],
"safari": [5.1, 6],
"opera": [12],
"iphone": [6],
"android": [4.2]
}
},
"repository": {
"type": "git",
"url": "git@github.com:michaelrhodes/piece-length.git"
},
"keywords": [
"piece",
"length",
"torrent"
],
"author": "Michael Rhodes",
"license": "MIT",
"bugs": {
"url": "https://github.com/michaelrhodes/piece-length/issues"
"test": "node test"
}
}
# piece-length
piece-length finds the optimal piece length for a given number of bytes. Optimal for what exactly? BitTorrent. [VuzeWiki](http://wiki.vuze.com/w/Torrent_Piece_Size) and [TorrentFreak](http://torrentfreak.com/how-to-make-the-best-torrents-081121/) have both released some examples of ideal piece lengths, and this algorithm will reproduce them.
[![Build status](https://travis-ci.org/michaelrhodes/piece-length.png?branch=master)](https://travis-ci.org/michaelrhodes/piece-length)
[![build status](https://travis-ci.org/michaelrhodes/piece-length.png?branch=master)](https://travis-ci.org/michaelrhodes/piece-length)
[![Browser support](https://ci.testling.com/michaelrhodes/piece-length.png)](https://ci.testling.com/michaelrhodes/piece-length)
## Install
## install
```

@@ -13,3 +11,3 @@ npm install piece-length

### Example
### use
``` js

@@ -22,3 +20,3 @@ var optimum = require('piece-length')

### License
### obey
[MIT](http://opensource.org/licenses/MIT)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc