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