@torrent-tv/proxy 2.89.0 → 2.89.1

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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @file A file kept whole is read from the disk by the subtitle walk.
3
+ *
4
+ * Once a file is kept whole its pieces leave the torrent's store while the
5
+ * bitfield still says they are held, and a read through the torrent waited on
6
+ * a store that no longer had them (field 2026-10-01). The reading itself is
7
+ * checked here over a temporary file; the client that uses it starts the
8
+ * torrent thread and is not built.
9
+ */
10
+
11
+ import test from "node:test";
12
+ import assert from "node:assert/strict";
13
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
14
+ import os from "node:os";
15
+ import path from "node:path";
16
+
17
+ import { readWholeFile } from "../services/torrent/worker/client.js";
18
+
19
+ test("a range of a whole file is read from the disk, and a range past it is not here", async (t) => {
20
+ const dir = await mkdtemp(path.join(os.tmpdir(), "ttv-whole-"));
21
+ t.after(() => rm(dir, { recursive: true, force: true }));
22
+ const file = path.join(dir, "film.mkv");
23
+ await writeFile(file, Buffer.from("0123456789"));
24
+ const whole = { path: file, length: 10, name: "film.mkv" };
25
+
26
+ assert.equal((await readWholeFile(whole, 2, 5)).toString(), "2345");
27
+ assert.equal((await readWholeFile(whole, 8, 20)).toString(), "89", "clamped to the file");
28
+ assert.equal(await readWholeFile(whole, 12, 20), null);
29
+ await assert.rejects(readWholeFile({ ...whole, path: path.join(dir, "gone.mkv") }, 0, 1), { code: "ENOENT" });
30
+ });