piece-length
Advanced tools
Comparing version 1.0.0 to 1.0.1
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
3861
5
92
3
21
1
1
- Removedclosest-to@~2.0.0
- Removedclosest-to@2.0.0(transitive)