mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-10 04:22:16 +10:00
feat: add file reader
This commit is contained in:
@ -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 });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user