Comparing version 0.1.5 to 0.2.0
@@ -0,3 +1,5 @@ | ||
/* | ||
* (c) 2011 Tim Becker, see file LICENSE for details | ||
*/ | ||
/* | ||
@@ -120,2 +122,3 @@ * Provides functionality for bencoding and decoding as use in | ||
var neg = false | ||
var strLen = 0 | ||
@@ -127,3 +130,2 @@ this.parse = function (buffer, encoding) { | ||
} | ||
var strLen = 0 | ||
for (var pos = 0; pos != buffer.length; ++pos) { | ||
@@ -130,0 +132,0 @@ |
57
bla.js
@@ -1,7 +0,52 @@ | ||
fs = require('fs') | ||
benc = require('bncode') | ||
file = 'test/test.torrent' | ||
data = fs.readFileSync(file, 'binary') | ||
console.log(data) | ||
console.log(benc.decode(data)) | ||
var hexy = require("hexy").hexy, | ||
benc = require("./bencode.js"), | ||
fs = require("fs") | ||
function dumpFileFile(filename, cb) { | ||
fs.readFile(filename, function (err, data){ | ||
if (err) throw err; | ||
//p(hexy(data)) | ||
_p(data.toString()) | ||
cb() | ||
}) | ||
} | ||
function dumpFileStream(filename, cb) { | ||
var rstr = fs.createReadStream(filename) | ||
rstr.on('data', function(data){ | ||
// p(hexy(data)) | ||
//p(data) | ||
_p(data.toString()) | ||
_p(".") | ||
}) | ||
rstr.on('end', function() {cb()}) | ||
} | ||
function p (m) { | ||
console.log(m) | ||
} | ||
function _p(data) { | ||
process.stdout.write(data) | ||
} | ||
function usage(mes) { | ||
p("usage: [node] bla.js torrent_filename") | ||
p(mes) | ||
process.exit() | ||
} | ||
var fname = process.argv[2] | ||
if (!fname) { | ||
usage("provide filename"); | ||
} | ||
//dumpFileFile(fname, function(){}) | ||
dumpFileStream(fname, function(){}) | ||
{ | ||
"name" : "bncode", | ||
"version" : "0.1.5", | ||
"version" : "0.2.0", | ||
"description" : "bittorrent bencoding and decoding.", | ||
@@ -5,0 +5,0 @@ "author" : "Tim Becker <tim.becker@kuriositaet.de>", |
@@ -1,7 +0,20 @@ | ||
bencoding for JS (node.js) | ||
==== | ||
# bencoding for JS (node.js) | ||
This is a small library to encode and decode bencoded (bittorrent) | ||
Encoding is as follows: | ||
This is a small library to encode and decode bencoded (bittorrent) stuff. Bencoding is specified [here](http://www.bittorrent.org/beps/bep_0003.html). | ||
## Get & Install | ||
github repository is [here](https://github.com/a2800276/bencode.js) | ||
Installable via npm (npm package name is **bncode**, note spelling!): | ||
npm install bncode | ||
## Encoding | ||
Encoding works as follows: | ||
var benc = require("bencode"), | ||
@@ -26,3 +39,6 @@ exmp = {} | ||
Decoding will work in progressively, e.g. if you're receiving partial | ||
## Decoding | ||
Decoding will work progressively, e.g. if you're receiving partial | ||
bencoded strings on the network: | ||
@@ -57,3 +73,42 @@ | ||
be strings of (ascii) characters and if they weren't decoded as JS | ||
Strings, dict's would map to Javascript objects with properties. | ||
Strings, dict's couldn't be mapped to Javascript objects with properties. | ||
## Mapping bencoding to Javascript | ||
+----------------------------------------------------+ | ||
| | | | ||
| Bencoded | Javascript | | ||
|====================================================| | ||
| Strings | node Buffers, unless they are | | ||
| | Dictionary keys, in which case | | ||
| | they become Javascript Strings | | ||
|----------------+-----------------------------------| | ||
| Integers | Number | | ||
|----------------+-----------------------------------| | ||
| Lists | Array | | ||
|----------------+-----------------------------------| | ||
| Dictionaries | Object | | ||
| | | | ||
+----------------------------------------------------+ | ||
## Mapping Javascript to bencoding | ||
The library make a best effort to encode Javascript to bencoding. If you stick to basic types (Arrays, Objects with String keys and basic values, Strings, Buffers and Numbers) you should encounter suprises. Expect surprises (mainly not being able to round-trip encode/decode) if you encode fancies data. | ||
## Author | ||
bencode.js was written by Tim Becker (tim.becker@kuriositaet.de) I can be reached via email or (preferably) submit a bug to the github repository. | ||
## Thanks | ||
Roly Fentanes (fent) for bug reports. | ||
## License | ||
MIT, see `LICENSE` |
@@ -8,3 +8,3 @@ | ||
console.log(msg) | ||
process.stdout.flush() | ||
// process.stdout.flush() | ||
} | ||
@@ -268,2 +268,22 @@ | ||
function file_readStream (filename) { | ||
var fs = require('fs') | ||
var rs = fs.createReadStream(filename); | ||
var decoder = new benc.decoder(); | ||
rs.on('data', function(data) { | ||
try { | ||
decoder.decode(data); | ||
} catch (err) { | ||
fs.close(rs.fd); | ||
throw err; | ||
} | ||
}); | ||
rs.on('end', function() { | ||
}); | ||
} | ||
function file_bug() { | ||
@@ -302,3 +322,7 @@ var fs = require('fs') | ||
file_bug() | ||
//file_readStream("test/bloeh.torrent"); | ||
//console.log("here") | ||
file_readStream("test/chipcheezum.torrent"); | ||
file_readStream("test/videos.torrent"); | ||
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a 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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
1088814
16
706
113
0
3