From fe43f79062236df20824ea7ac336d412866c4da2 Mon Sep 17 00:00:00 2001 From: DecDuck Date: Fri, 30 May 2025 20:55:53 +1000 Subject: [PATCH] chore: bump version and add test --- __test__/utils.spec.mjs | 31 ++++++++++++++++++++++++++++--- index.d.ts | 2 +- package.json | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/__test__/utils.spec.mjs b/__test__/utils.spec.mjs index ba5f7cf..c94656a 100644 --- a/__test__/utils.spec.mjs +++ b/__test__/utils.spec.mjs @@ -28,11 +28,11 @@ test("read file", async (t) => { if (fs.existsSync(dirName)) fs.rmSync(dirName, { recursive: true }); fs.mkdirSync(dirName, { recursive: true }); - const testString = "g'day what's up my koala bros\n".repeat(10000); + const testString = "g'day what's up my koala bros\n".repeat(1000); - fs.writeFileSync("./.test2/TESTFILE", testString); + fs.writeFileSync(dirName + "/TESTFILE", testString); - const stream = droplet.readFile("./.test2", "TESTFILE"); + const stream = droplet.readFile(dirName, "TESTFILE"); let finalString = ""; @@ -44,3 +44,28 @@ test("read file", async (t) => { t.assert(finalString == testString, "file strings don't match"); fs.rmSync(dirName, { recursive: true }); }); + + +test("read file offset", async (t) => { + const dirName = "./.test3"; + if (fs.existsSync(dirName)) fs.rmSync(dirName, { recursive: true }); + fs.mkdirSync(dirName, { recursive: true }); + + const testString = "0123456789"; + + fs.writeFileSync(dirName + "/TESTFILE", testString); + + const stream = droplet.readFile(dirName, "TESTFILE", 1, 4); + + let finalString = ""; + + for await (const chunk of stream) { + // Do something with each 'chunk' + finalString += String.fromCharCode.apply(null, chunk); + } + + const expectedString = testString.slice(1, 5); + + t.assert(finalString == expectedString, "file strings don't match"); + fs.rmSync(dirName, { recursive: true }); +}); diff --git a/index.d.ts b/index.d.ts index 49b2e57..0def66b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,7 +12,7 @@ export declare function hasBackendForPath(path: string): boolean export declare function listFiles(path: string): Array -export declare function readFile(path: string, subPath: string): ReadableStream | null +export declare function readFile(path: string, subPath: string, start?: number | undefined | null, end?: number | undefined | null): ReadableStream | null export declare function signNonce(privateKey: string, nonce: string): string diff --git a/package.json b/package.json index 17472dc..4b765a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@drop-oss/droplet", - "version": "1.3.0", + "version": "1.3.1", "main": "index.js", "types": "index.d.ts", "napi": {