@ctrl/torrent-file 4.0.0 → 4.1.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.
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-bitwise */
1
2
  // str1 > str2: 1
2
3
  // str1 === str2: 0
3
4
  // str1 < str2: -1
@@ -54,6 +55,7 @@ export const isValidUTF8 = (buf) => {
54
55
  if (buf[i + 1] >> 6 === 2) {
55
56
  i += 2;
56
57
  continue;
58
+ // biome-ignore lint/style/noUselessElse: false positive
57
59
  }
58
60
  else {
59
61
  return false;
@@ -1,7 +1,8 @@
1
+ export declare const sha1: (input: Uint8Array) => string;
1
2
  /**
2
3
  * sha1 of torrent file info. This hash is commenly used by torrent clients as the ID of the torrent.
3
4
  */
4
- export declare function hash(file: Uint8Array): Promise<string>;
5
+ export declare function hash(file: Uint8Array): string;
5
6
  export interface TorrentFileData {
6
7
  length: number;
7
8
  files: Array<{
@@ -1,11 +1,17 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { join, sep } from 'node:path';
2
- import { sha1 } from 'crypto-hash';
3
3
  import { isUint8Array, uint8ArrayToHex, uint8ArrayToString } from 'uint8array-extras';
4
4
  import { decode, encode } from './bencode/index.js';
5
+ export const sha1 = (input) => {
6
+ const hash = createHash('sha1');
7
+ // Update the hash object with the data
8
+ hash.update(input);
9
+ return hash.digest('hex');
10
+ };
5
11
  /**
6
12
  * sha1 of torrent file info. This hash is commenly used by torrent clients as the ID of the torrent.
7
13
  */
8
- export async function hash(file) {
14
+ export function hash(file) {
9
15
  const torrent = decode(file);
10
16
  return sha1(encode(torrent.info));
11
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctrl/torrent-file",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Parse a torrent file (name, hash, files, pieces)",
5
5
  "author": "Scott Cooper <scttcper@gmail.com>",
6
6
  "license": "MIT",
@@ -16,9 +16,9 @@
16
16
  "scripts": {
17
17
  "lint": "pnpm run '/^(lint:biome|lint:eslint)$/'",
18
18
  "lint:biome": "biome check .",
19
- "lint:eslint": "eslint --ext .ts,.tsx .",
19
+ "lint:eslint": "eslint .",
20
20
  "lint:fix": "pnpm run '/^(lint:biome|lint:eslint):fix$/'",
21
- "lint:eslint:fix": "eslint --ext .ts,.tsx . --fix",
21
+ "lint:eslint:fix": "eslint . --fix",
22
22
  "lint:biome:fix": "biome check . --apply",
23
23
  "prepare": "npm run build",
24
24
  "build": "tsc",
@@ -27,18 +27,17 @@
27
27
  "test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
28
28
  },
29
29
  "dependencies": {
30
- "crypto-hash": "^3.0.0",
31
- "uint8array-extras": "^1.1.0"
30
+ "uint8array-extras": "^1.4.0"
32
31
  },
33
32
  "devDependencies": {
34
- "@biomejs/biome": "1.6.0",
35
- "@ctrl/eslint-config-biome": "2.1.1",
36
- "@sindresorhus/tsconfig": "5.0.0",
37
- "@types/node": "20.11.25",
38
- "@vitest/coverage-v8": "1.3.1",
39
- "parse-torrent": "11.0.16",
40
- "typescript": "5.4.2",
41
- "vitest": "1.3.1"
33
+ "@biomejs/biome": "1.8.3",
34
+ "@ctrl/eslint-config-biome": "4.2.1",
35
+ "@sindresorhus/tsconfig": "6.0.0",
36
+ "@types/node": "22.5.4",
37
+ "@vitest/coverage-v8": "2.0.5",
38
+ "parse-torrent": "11.0.17",
39
+ "typescript": "5.6.2",
40
+ "vitest": "2.0.5"
42
41
  },
43
42
  "publishConfig": {
44
43
  "access": "public",