Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.11 KB

README.md

File metadata and controls

41 lines (27 loc) · 1.11 KB

streaming-bencode

A streaming bencode decoder for Node.js written using ECMAScript 6 generators. Can parse any bencoded value in a stream of bencoded values.

Installation

npm install streaming-bencode

Examples:

var bencoder = require('streaming-bencode'),
  ReadableStream = require('stream').Readable;
  
var source = new Readable();

source._read = function () {};

source.push('d5:elistle6:elist2l0:0:0:0:1:12:22e0:0:6:string11:Hello World7:integeri12345e10:dictionaryd3:key36:This is a string within a dictionarye4:listli1ei2ei3ei4e6:stringi5edeee');

source.pipe(bencoder.transformer()).on('data', console.log);

{ elist: [],
  elist2: [ '', '', '', '', '1', '22' ],
  '': '',
  string: 'Hello World',
  integer: 12345,
  dictionary: { key: 'This is a string within a dictionary' },
  list: [ 1, 2, 3, 4, 'string', 5, {} ] }

Example (Decode as you type):

var bencoder = require('streaming-bencode');

process.stdin.setRawMode(true); // override default cooked mode
process.stdin.pipe(bencoder.transformer()).on('data', console.log.bind(console, 'Parsed'));