Comparing version 0.11.0 to 0.12.0
@@ -0,1 +1,7 @@ | ||
const INTEGER_START = 0x69 // 'i' | ||
const STRING_DELIM = 0x3A // ':' | ||
const DICTIONARY_START = 0x64 // 'd' | ||
const LIST_START = 0x6C // 'l' | ||
const END_OF_TYPE = 0x65 // 'e' | ||
/** | ||
@@ -85,7 +91,7 @@ * replaces parseInt(buffer.toString('ascii', start, end)). | ||
switch (decode.data[decode.position]) { | ||
case 0x64: | ||
case DICTIONARY_START: | ||
return decode.dictionary() | ||
case 0x6C: | ||
case LIST_START: | ||
return decode.list() | ||
case 0x69: | ||
case INTEGER_START: | ||
return decode.integer() | ||
@@ -119,3 +125,3 @@ default: | ||
while (decode.data[decode.position] !== 0x65) { | ||
while (decode.data[decode.position] !== END_OF_TYPE) { | ||
dict[decode.buffer()] = decode.next() | ||
@@ -134,3 +140,3 @@ } | ||
while (decode.data[decode.position] !== 0x65) { | ||
while (decode.data[decode.position] !== END_OF_TYPE) { | ||
lst.push(decode.next()) | ||
@@ -145,3 +151,3 @@ } | ||
decode.integer = function () { | ||
var end = decode.find(0x65) | ||
var end = decode.find(END_OF_TYPE) | ||
var number = getIntFromBuffer(decode.data, decode.position + 1, end) | ||
@@ -155,3 +161,3 @@ | ||
decode.buffer = function () { | ||
var sep = decode.find(0x3A) | ||
var sep = decode.find(STRING_DELIM) | ||
var length = getIntFromBuffer(decode.data, decode.position, sep) | ||
@@ -158,0 +164,0 @@ var end = ++sep + length |
@@ -28,3 +28,3 @@ /** | ||
if (Buffer.isBuffer(data)) { | ||
buffers.push(new Buffer(data.length + ':')) | ||
buffers.push(Buffer.from(data.length + ':')) | ||
buffers.push(data) | ||
@@ -54,8 +54,8 @@ return | ||
var buffE = new Buffer('e') | ||
var buffD = new Buffer('d') | ||
var buffL = new Buffer('l') | ||
var buffE = Buffer.from('e') | ||
var buffD = Buffer.from('d') | ||
var buffL = Buffer.from('l') | ||
encode.buffer = function (buffers, data) { | ||
buffers.push(new Buffer(Buffer.byteLength(data) + ':' + data)) | ||
buffers.push(Buffer.from(Buffer.byteLength(data) + ':' + data)) | ||
} | ||
@@ -69,3 +69,3 @@ | ||
buffers.push(new Buffer('i' + val + 'e')) | ||
buffers.push(Buffer.from('i' + val + 'e')) | ||
@@ -72,0 +72,0 @@ if (val !== data && !encode._floatConversionDetected) { |
{ | ||
"name": "bencode", | ||
"description": "Bencode de/encoder", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"bugs": { | ||
@@ -23,6 +23,7 @@ "url": "https://github.com/themasch/node-bencode/issues" | ||
"bncode": "latest", | ||
"btparse": "latest", | ||
"dht-bencode": "latest", | ||
"dht.js": "latest", | ||
"matcha": "~0.7.0", | ||
"standard": "^8.1.0", | ||
"standard": "^9.0.2", | ||
"tap-spec": "~4.1.0", | ||
@@ -46,4 +47,5 @@ "tape": "~4.6.0" | ||
"bench": "matcha", | ||
"style": "standard --fix", | ||
"test": "standard && tape test/*.test.js | tap-spec" | ||
} | ||
} |
@@ -44,8 +44,9 @@ # Bencode | ||
package | version | op/sec | ||
----------- | ------- | ------ | ||
bencode | 1.0.0 | 41,880 | ||
dht.js | 0.2.16 | 36,824 | ||
dht-bencode | 0.1.2 | 25,232 | ||
bencoding | 0.0.1 | 19,129 | ||
bncode | 0.5.3 | 16,567 | ||
----------- | ------- | --------- | ||
bencode | 0.12.0 | *47,692* | ||
dht.js | 0.2.16 | 43,908 | ||
dht-bencode | 0.1.2 | 35,670 | ||
bencoding | 0.0.1 | 31,942 | ||
bncode | 0.5.3 | 25,097 | ||
bparse | 1.0.2 | - | ||
@@ -56,9 +57,10 @@ ### decode to buffer | ||
----------- | ------- | ------ | ||
bencode | 1.0.0 | 67,351 | ||
dht-bencode | 0.1.2 | 64,445 | ||
bencoding | 0.0.1 | 48,415 | ||
dht.js | 0.2.16 | 41,648 | ||
bncode | 0.5.3 | 3,188 | ||
bencode | 0.12.0 | 129,326 | ||
dht.js | 0.2.16 | 71,639 | ||
dht-bencode | 0.1.2 | 89,285 | ||
bencoding | 0.0.1 | 97,285 | ||
bncode | 0.5.3 | 16,567 | ||
bparse | 1.0.2 | *155,660* | ||
_Benchmarks run on an Intel Core i7-5500U @ 2.40Ghz with node v6.1.0 & GNU/Linux 4.4.0_ | ||
_Benchmarks run on an Intel Core i7-4600M @ 2.90Ghz with node v7.8.0 & GNU/Linux 4.4.39_ | ||
@@ -107,3 +109,3 @@ To run the benchmarks simply use | ||
```javascript | ||
var data = new Buffer( 'd6:string11:Hello World7:integeri12345e4:dictd3:key36:This is a string within a dictionarye4:listli1ei2ei3ei4e6:stringi5edeee' ) | ||
var data = Buffer.from('d6:string11:Hello World7:integeri12345e4:dictd3:key36:This is a string within a dictionarye4:listli1ei2ei3ei4e6:stringi5edeee') | ||
var result = bencode.decode( data ) | ||
@@ -110,0 +112,0 @@ ``` |
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
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
14905
234
170
9