Gathering detailed insights and metrics for bencode
Gathering detailed insights and metrics for bencode
Gathering detailed insights and metrics for bencode
Gathering detailed insights and metrics for bencode
npm install bencode
93.6
Supply Chain
99.5
Quality
83.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
166 Stars
367 Commits
36 Forks
4 Watching
11 Branches
34 Contributors
Updated on 27 Nov 2024
JavaScript (99.65%)
HTML (0.35%)
Cumulative downloads
Total Downloads
Last day
9.1%
2,528
Compared to previous day
Last week
-10%
14,145
Compared to previous week
Last month
-4.2%
58,495
Compared to previous month
Last year
-66.6%
643,554
Compared to previous year
A node library for encoding and decoding bencoded data, according to the BitTorrent specification.
from Wikipedia:
Bencode (pronounced like B encode) is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data.
It supports four different types of values:
Bencoding is most commonly used in torrent files. These metadata files are simply bencoded dictionaries.
npm install bencode
1import bencode from 'bencode'
You can also use node-bencode with browserify to be able to use it in a lot of modern browsers.
1 2var data = { 3 string: 'Hello World', 4 integer: 12345, 5 dict: { 6 key: 'This is a string within a dictionary' 7 }, 8 list: [ 1, 2, 3, 4, 'string', 5, {} ] 9} 10 11var result = bencode.encode( data ) 12
NOTE As of bencode@0.8.0
, boolean values will be cast to integers (false -> 0, true -> 1).
d4:dictd3:key36:This is a string within a dictionarye7:integeri12345e4:listli1ei2ei3ei4e6:stringi5edee6:string11:Hello Worlde
1var data = Buffer.from('d6:string11:Hello World7:integeri12345e4:dictd3:key36:This is a string within a dictionarye4:listli1ei2ei3ei4e6:stringi5edeee') 2var result = bencode.decode( data )
1{ 2 string: <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>, 3 integer: 12345, 4 dict: { 5 key: <Buffer 54 68 69 73 20 69 73 20 61 20 73 74 72 69 6e 67 20 77 69 74 68 69 6e 20 61 20 64 69 63 74 69 6f 6e 61 72 79> 6 }, 7 list: [ 1, 2, 3, 4, <Buffer 73 74 72 69 6e 67>, 5, {} ] 8}
Automagically convert bytestrings to strings:
1var result = bencode.decode( data, 'utf8' )
1{ 2 string: 'Hello World', 3 integer: 12345, 4 dict: { 5 key: 'This is a string within a dictionary' 6 }, 7 list: [ 1, 2, 3, 4, 'string', 5, {} ] 8}
The API is compatible with the abstract-encoding
specification.
Buffer
|Array
|String
|Object
|Number
|Boolean
dataBuffer
bufferNumber
offset
Returns Buffer
Buffer
dataNumber
startNumber
endString
encoding
If encoding
is set, bytestrings are
automatically converted to strings.
Returns Object
| Array
| Buffer
| String
| Number
Buffer
|Array
|String
|Object
|Number
|Boolean
value
No vulnerabilities found.
No security vulnerabilities found.