@ctrl/torrent-file 4.1.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -4
- package/dist/src/bencode/decode.js +1 -1
- package/dist/src/bencode/utils.js +1 -5
- package/package.json +39 -17
package/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# torrent-file [](https://www.npmjs.com/package/@ctrl/torrent-file) [](https://codecov.io/gh/scttcper/torrent-file) [](https://bundlephobia.com/result?p=@ctrl/torrent-file)
|
2
2
|
|
3
|
-
> Parse a torrent file and read encoded data.
|
3
|
+
> Parse a torrent file and read encoded data.
|
4
4
|
|
5
5
|
This project is based on [parse-torrent](https://www.npmjs.com/package/parse-torrent) and [node-bencode](https://github.com/themasch/node-bencode) to parse the data of a torrent file. This library implements its own [bencode](http://www.bittorrent.org/beps/bep_0003.html) encoder and decoder that does not use `Buffer`.
|
6
6
|
|
7
7
|
### Install
|
8
|
+
|
8
9
|
```console
|
9
10
|
npm install @ctrl/torrent-file
|
10
11
|
```
|
@@ -12,9 +13,12 @@ npm install @ctrl/torrent-file
|
|
12
13
|
### API
|
13
14
|
|
14
15
|
##### info
|
16
|
+
|
15
17
|
The content of the metainfo file.
|
18
|
+
|
16
19
|
```ts
|
17
20
|
import fs from 'fs';
|
21
|
+
|
18
22
|
import { info } from '@ctrl/torrent-file';
|
19
23
|
|
20
24
|
const torrentInfo = info(fs.readFileSync('myfile'));
|
@@ -22,9 +26,12 @@ console.log({ torrentInfo });
|
|
22
26
|
```
|
23
27
|
|
24
28
|
##### files
|
29
|
+
|
25
30
|
data about the files described in the torrent file, includes hashes of the pieces
|
31
|
+
|
26
32
|
```ts
|
27
33
|
import fs from 'fs';
|
34
|
+
|
28
35
|
import { files } from '@ctrl/torrent-file';
|
29
36
|
|
30
37
|
const torrentFiles = files(fs.readFileSync('myfile'));
|
@@ -32,18 +39,21 @@ console.log({ torrentFiles });
|
|
32
39
|
```
|
33
40
|
|
34
41
|
##### hash
|
42
|
+
|
35
43
|
sha1 of torrent file info. This hash is commenly used by torrent clients as the ID of the torrent. It is async and sha1 encoding is handled by [crypto-hash](https://github.com/sindresorhus/crypto-hash)
|
44
|
+
|
36
45
|
```ts
|
37
46
|
import fs from 'fs';
|
47
|
+
|
38
48
|
import { hash } from '@ctrl/torrent-file';
|
39
49
|
|
40
50
|
(async () => {
|
41
51
|
const torrentHash = await hash(fs.readFileSync('myfile'));
|
42
52
|
console.log({ torrentHash });
|
43
|
-
})()
|
53
|
+
})();
|
44
54
|
```
|
45
55
|
|
46
|
-
|
47
56
|
### See Also
|
57
|
+
|
48
58
|
[parse-torrent](https://www.npmjs.com/package/parse-torrent) - "@ctrl/torrent-file" torrent parsing based very heavily off this project
|
49
|
-
[node-bencode](https://github.com/themasch/node-bencode) - bencoder built into this project heavily based off this project
|
59
|
+
[node-bencode](https://github.com/themasch/node-bencode) - bencoder built into this project heavily based off this project
|
@@ -1,4 +1,3 @@
|
|
1
|
-
/* eslint-disable no-bitwise */
|
2
1
|
// str1 > str2: 1
|
3
2
|
// str1 === str2: 0
|
4
3
|
// str1 < str2: -1
|
@@ -55,11 +54,8 @@ export const isValidUTF8 = (buf) => {
|
|
55
54
|
if (buf[i + 1] >> 6 === 2) {
|
56
55
|
i += 2;
|
57
56
|
continue;
|
58
|
-
// biome-ignore lint/style/noUselessElse: false positive
|
59
|
-
}
|
60
|
-
else {
|
61
|
-
return false;
|
62
57
|
}
|
58
|
+
return false;
|
63
59
|
}
|
64
60
|
// UTF8-3 = %xE0 %xA0-BF UTF8-tail
|
65
61
|
// UTF8-3 = %xED %x80-9F UTF8-tail
|
package/package.json
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ctrl/torrent-file",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.3.0",
|
4
4
|
"description": "Parse a torrent file (name, hash, files, pieces)",
|
5
5
|
"author": "Scott Cooper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
7
|
-
"repository":
|
7
|
+
"repository": {
|
8
|
+
"type": "git",
|
9
|
+
"url": "git+https://github.com/scttcper/torrent-file.git"
|
10
|
+
},
|
8
11
|
"type": "module",
|
9
12
|
"exports": "./dist/src/index.js",
|
10
13
|
"types": "./dist/src/index.d.ts",
|
@@ -14,12 +17,8 @@
|
|
14
17
|
"sideEffects": false,
|
15
18
|
"keywords": [],
|
16
19
|
"scripts": {
|
17
|
-
"lint": "
|
18
|
-
"lint:
|
19
|
-
"lint:eslint": "eslint .",
|
20
|
-
"lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
|
21
|
-
"lint:eslint:fix": "eslint . --fix",
|
22
|
-
"lint:biome:fix": "biome check . --apply",
|
20
|
+
"lint": "oxlint . && prettier --check . --experimental-cli",
|
21
|
+
"lint:fix": "oxlint . --fix && prettier --write . --log-level=error --experimental-cli",
|
23
22
|
"prepare": "npm run build",
|
24
23
|
"build": "tsc",
|
25
24
|
"test": "vitest run",
|
@@ -27,18 +26,41 @@
|
|
27
26
|
"test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
|
28
27
|
},
|
29
28
|
"dependencies": {
|
30
|
-
"uint8array-extras": "^1.
|
29
|
+
"uint8array-extras": "^1.5.0"
|
31
30
|
},
|
32
31
|
"devDependencies": {
|
33
|
-
"@
|
34
|
-
"@
|
35
|
-
"@
|
36
|
-
"@types/node": "
|
37
|
-
"@vitest/coverage-v8": "2.
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
32
|
+
"@ctrl/oxlint-config": "1.2.7",
|
33
|
+
"@sindresorhus/tsconfig": "8.0.1",
|
34
|
+
"@trivago/prettier-plugin-sort-imports": "5.2.2",
|
35
|
+
"@types/node": "24.6.2",
|
36
|
+
"@vitest/coverage-v8": "3.2.4",
|
37
|
+
"oxlint": "1.19.0",
|
38
|
+
"parse-torrent": "11.0.18",
|
39
|
+
"prettier": "3.6.2",
|
40
|
+
"typescript": "5.9.3",
|
41
|
+
"vitest": "3.2.4"
|
42
|
+
},
|
43
|
+
"prettier": {
|
44
|
+
"singleQuote": true,
|
45
|
+
"trailingComma": "all",
|
46
|
+
"arrowParens": "avoid",
|
47
|
+
"semi": true,
|
48
|
+
"printWidth": 100,
|
49
|
+
"plugins": [
|
50
|
+
"@trivago/prettier-plugin-sort-imports"
|
51
|
+
],
|
52
|
+
"importOrder": [
|
53
|
+
"^node:.*$",
|
54
|
+
"<THIRD_PARTY_MODULES>",
|
55
|
+
"^(@ctrl)(/.*|$)",
|
56
|
+
"^\\.\\./(?!.*\\.css$)",
|
57
|
+
"^\\./(?!.*\\.css$)(?=.*/)",
|
58
|
+
"^\\./(?!.*\\.css$)(?!.*/)"
|
59
|
+
],
|
60
|
+
"importOrderSeparation": true,
|
61
|
+
"importOrderSortSpecifiers": false
|
41
62
|
},
|
63
|
+
"packageManager": "pnpm@10.18.0",
|
42
64
|
"publishConfig": {
|
43
65
|
"access": "public",
|
44
66
|
"provenance": true
|