mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-09 20:12:18 +10:00
chore: bump version and add test
This commit is contained in:
@ -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 });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user