@ctrl/torrent-file 4.2.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 CHANGED
@@ -1,10 +1,11 @@
1
1
  # torrent-file [![npm](https://badgen.net/npm/v/@ctrl/torrent-file)](https://www.npmjs.com/package/@ctrl/torrent-file) [![coverage](https://badgen.net/codecov/c/github/scttcper/torrent-file)](https://codecov.io/gh/scttcper/torrent-file) [![bundlesize](https://badgen.net/bundlephobia/min/@ctrl/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
@@ -2,8 +2,8 @@ import { stringToUint8Array, uint8ArrayToString } from 'uint8array-extras';
2
2
  import { isValidUTF8 } from './utils.js';
3
3
  const td = new TextDecoder();
4
4
  class Decoder {
5
- buf;
6
5
  idx = 0;
6
+ buf;
7
7
  constructor(buf) {
8
8
  this.buf = buf;
9
9
  }
@@ -53,7 +53,6 @@ export const encode = (data) => {
53
53
  if (Array.isArray(data)) {
54
54
  return encodeArray(data);
55
55
  }
56
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
57
56
  switch (typeof data) {
58
57
  case 'string': {
59
58
  return encodeString(data);
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/torrent-file",
3
- "version": "4.2.0",
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",
@@ -17,12 +17,8 @@
17
17
  "sideEffects": false,
18
18
  "keywords": [],
19
19
  "scripts": {
20
- "lint": "pnpm run '/^(lint:biome|lint:eslint)$/'",
21
- "lint:biome": "biome check .",
22
- "lint:eslint": "eslint .",
23
- "lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
24
- "lint:eslint:fix": "eslint . --fix",
25
- "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",
26
22
  "prepare": "npm run build",
27
23
  "build": "tsc",
28
24
  "test": "vitest run",
@@ -30,18 +26,41 @@
30
26
  "test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
31
27
  },
32
28
  "dependencies": {
33
- "uint8array-extras": "^1.4.0"
29
+ "uint8array-extras": "^1.5.0"
34
30
  },
35
31
  "devDependencies": {
36
- "@biomejs/biome": "1.9.4",
37
- "@ctrl/eslint-config-biome": "4.3.1",
38
- "@sindresorhus/tsconfig": "7.0.0",
39
- "@types/node": "22.10.7",
40
- "@vitest/coverage-v8": "3.0.2",
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",
41
38
  "parse-torrent": "11.0.18",
42
- "typescript": "5.7.3",
43
- "vitest": "3.0.2"
39
+ "prettier": "3.6.2",
40
+ "typescript": "5.9.3",
41
+ "vitest": "3.2.4"
44
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
62
+ },
63
+ "packageManager": "pnpm@10.18.0",
45
64
  "publishConfig": {
46
65
  "access": "public",
47
66
  "provenance": true