feat: add file reader

This commit is contained in:
DecDuck
2025-05-28 15:03:45 +10:00
parent 7811818a72
commit cc94798962
4 changed files with 14 additions and 15 deletions

7
.gitignore vendored
View File

@ -9,7 +9,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.test
.test*
.tsimp
# Diagnostic reports (https://nodejs.org/api/report.html)
@ -201,7 +201,4 @@ test.mjs
manifest.json
# JetBrains
.idea
TESTFILE
.idea

View File

@ -1 +0,0 @@
g'day what's up my koala bros

View File

@ -8,16 +8,16 @@ test("check alt thread util", async (t) => {
let endtime1, endtime2;
droplet.callAltThreadFunc(async () => {
await new Promise((r) => setTimeout(r, 1000));
await new Promise((r) => setTimeout(r, 100));
endtime1 = Date.now();
});
await new Promise((r) => setTimeout(r, 5000));
await new Promise((r) => setTimeout(r, 500));
endtime2 = Date.now();
const difference = endtime2 - endtime1;
if (difference > 4100 || difference < 3900) {
t.fail("timing is not close enough");
if (difference > 500 || difference < 300) {
t.fail("timing is not close enough: " + difference);
}
t.pass();
@ -28,16 +28,19 @@ test("read file", async (t) => {
if (fs.existsSync(dirName)) fs.rmSync(dirName, { recursive: true });
fs.mkdirSync(dirName, { recursive: true });
fs.writeFileSync("./.test2/TESTFILE", "g'day what's up my koala bros");
const testString = "g'day what's up my koala bros\n".repeat(10000);
fs.writeFileSync("./.test2/TESTFILE", testString);
const stream = droplet.readFile("./.test2", "TESTFILE");
console.log(stream);
let finalString = "";
for await (const chunk of stream) {
// Do something with each 'chunk'
console.log(chunk);
finalString += String.fromCharCode.apply(null, chunk);
}
t.pass();
t.assert(finalString == testString, "file strings don't match");
fs.rmSync(dirName, { recursive: true });
});

View File

@ -1,6 +1,6 @@
{
"name": "@drop-oss/droplet",
"version": "1.1.2",
"version": "1.2.0",
"main": "index.js",
"types": "index.d.ts",
"napi": {