Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bncode

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bncode - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

file.delete

6

bencode.js

@@ -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 @@

@@ -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");
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