mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-09 20:12:18 +10:00
feat: add file reader
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@ -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
|
||||
@ -1 +0,0 @@
|
||||
g'day what's up my koala bros
|
||||
@ -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 });
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@drop-oss/droplet",
|
||||
"version": "1.1.2",
|
||||
"version": "1.2.0",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"napi": {
|
||||
|
||||
Reference in New Issue
Block a user