feat: zip file reading

This commit is contained in:
DecDuck
2025-07-02 11:55:04 +10:00
parent c1aaf8adcd
commit 48e5b97a4e
8 changed files with 163 additions and 42 deletions

View File

@ -2,7 +2,7 @@ import test from "ava";
import fs from "node:fs";
import path from "path";
import droplet from "../index.js";
import droplet, { generateManifest } from "../index.js";
test("check alt thread util", async (t) => {
let endtime1, endtime2;
@ -45,7 +45,6 @@ test("read file", async (t) => {
fs.rmSync(dirName, { recursive: true });
});
test("read file offset", async (t) => {
const dirName = "./.test3";
if (fs.existsSync(dirName)) fs.rmSync(dirName, { recursive: true });
@ -65,6 +64,36 @@ test("read file offset", async (t) => {
const expectedString = testString.slice(1, 4);
t.assert(finalString == expectedString, "file strings don't match");
t.assert(
finalString == expectedString,
`file strings don't match: ${finalString} vs ${expectedString}`
);
fs.rmSync(dirName, { recursive: true });
});
test("zip file reader", async (t) => {
const manifest = JSON.parse(
await new Promise((r, e) =>
generateManifest(
"./assets/TheGame.zip",
(_, __) => {},
(_, __) => {},
(err, manifest) => (err ? e(err) : r(manifest))
)
)
);
console.log(manifest);
return t.pass();
const stream = droplet.readFile("./assets/TheGame.zip", "TheGame/setup.exe");
let finalString;
for await (const chunk of stream) {
console.log(`read chunk ${chunk}`);
// Do something with each 'chunk'
finalString += String.fromCharCode.apply(null, chunk);
}
console.log(finalString);
});