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

btparse

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

btparse - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

.editorconfig

26

index.js

@@ -1,3 +0,25 @@

var bt = require('./build/Release/btparse');
'use strict'
module.exports = bt;
var next = require('./lib/lexer')
var parser = require('./lib/parser')
var from = require('./lib/from')
module.exports = decode
function decode(data, opts) {
var buffer = Buffer.isBuffer(data) ? data : from(data)
opts = opts || {}
var depth = opts.depth >>> 0
var ptr = {
i: 0,
buffer: buffer,
length: buffer.length, // save space in IC
depth: depth < 1 ? Infinity : depth,
curr_depth: 0
}
return parser.select(ptr, next(ptr, -1))
}

31

package.json
{
"name": "btparse",
"version": "0.1.0",
"description": "Very fast way for parse torrent files. With C++ implementation, based on libtorrent.",
"version": "1.0.0",
"description": "A modern bencode parser focused on speed and perfomance",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"preinstall": "node-gyp rebuild",
"start":"node ./index.js"
"cover": "nyc --reporter=html --reporter=text npm test",
"test": "node test/reporter.js",
"bench": "matcha ./bench/decode.js"
},
"engines" : { "node" : ">=0.8 <0.11" },
"repository": {
"type": "git",
"url": "git://github.com/reklatsmasters/node-btparse.git"
"url": "git://github.com/reklatsmasters/btparse.git"
},

@@ -20,3 +19,2 @@ "keywords": [

"parser",
"c++",
"bencoder",

@@ -29,10 +27,17 @@ "bdecoder",

"name": "Dmitry Tsvettsikh",
"email": "dmitrycvet@gmail.com"
"email": "me@reklatsmasters.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/reklatsmasters/node-btparse/issues"
"url": "https://github.com/reklatsmasters/btparse/issues"
},
"homepage": "https://github.com/reklatsmasters/node-btparse",
"gypfile": true
}
"homepage": "https://github.com/reklatsmasters/btparse",
"dependencies": {},
"devDependencies": {
"bencode": "^0.11.0",
"buffer-compare": "^1.1.1",
"matcha": "^0.7.0",
"nyc": "^10.1.2",
"tape": "^4.6.3"
}
}

@@ -1,29 +0,63 @@

## Btparse
Very fast way for parse torrent files. With C++ implementation, based on libtorrent.
## btparse [![Build Status](https://travis-ci.org/ReklatsMasters/btparse.svg?branch=master)](https://travis-ci.org/ReklatsMasters/btparse) [![npm](https://img.shields.io/npm/v/btparse.svg)](https://npmjs.org/package/btparse) [![license](https://img.shields.io/npm/l/btparse.svg)](https://npmjs.org/package/btparse) [![downloads](https://img.shields.io/npm/dm/btparse.svg)](https://npmjs.org/package/btparse)
### Why only sync api?
Как известно nodejs однопоточен. Для создания асинхронного взаимодействия рабочая функция запускается в отдельном потоке, однако из этого потока мы не имеем доступа к структурам V8. Текущая реализация портирована из libtorrent и использует структуры V8 для хранения данных. Если же использовать некий внутренний безопасный тип для хранения данных, потом всё равно придётся перекидывать эти данные в v8::Value. А это усложнение просто не имеет смысла.
A modern bencode parser focused on speed and perfomance. It used [`recursive descent parser`](https://en.wikipedia.org/wiki/Recursive_descent_parser), a kind of [`top-down`](https://en.wikipedia.org/wiki/Top-down_parsing) parsers.
Current implementation used V8 structures and types in a decoder.
## Usage
## Install
````
npm install btparse
````
```js
// classic api
const decode = require('btparse')
// or you can use lazy parser
// const decode = require('btparse/lazy')
## Example
console.log(decode(torrent).info.name)
var bt = require("btparse")
, fs = require("fs")
;
fs.readFile("some.torrent", {encoding:null}, function(e, file){
var torrent = bt.decode(file); // Buffer for decode torrents
});
var list = bt.decode("li1ei2ei3ee"); // String for decode simple string
console.log(decode('d3:abcli13eee')) // {abc: [ 13 ]}
```
## Perfomance
*nodejs 6.9.1 / windows 10 x64 / i5 4690*
|Library| op/s | ms (1e5 op) |
|-------|:---:|:---:|
|bencode| 109,484| 887 |
|btparse| 139,477 | 696 |
|btparse#lazy|159,597|594 |
## API
##### `decode(input: Buffer|String, opts: Options) -> Object|Number|Array|Buffer`
Parse and decode bencoded message.
* **`opts.depth: Number`**
Max parse depth for objects; default = `infinity`, min = `1`
```js
const decode = require('btparse')
console.log(decode('d2:abi2e2:bbd2:ccleee', {depth: 1})) // {ab: 2, bb: Buffer.from('d2:cclee')}
```
## Lazy
##### `decode(input: Buffer|String) -> Proxy<Object>|Number|Array|Buffer`
The main difference is that **all** buffers aren't decoded into a string in parsing time. Required nodejs 6+.
```js
const decode = require('btparse/lazy')
// get prop
console.log(decode(torrent).info.name)
// check prop
console.log('name' in decode(torrent).info)
// get all keys / props
console.log(Reflect.ownKeys(decode(torrent)))
```
## License
MIT
MIT, (c) Dmitry Tsvettsikh, 2017+

Sorry, the diff of this file is not supported yet

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