Comparing version 0.1.0 to 1.0.0
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)) | ||
} |
{ | ||
"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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
50153
25
721
0
64
1
5
5