mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-09 20:12:18 +10:00
feat: add zip speed test
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import test from "ava";
|
||||
import fs from "node:fs";
|
||||
import path from "path";
|
||||
import prettyBytes from "pretty-bytes";
|
||||
|
||||
import droplet, { DropletHandler, generateManifest } from "../index.js";
|
||||
|
||||
@ -78,7 +79,12 @@ test("read file offset", async (t) => {
|
||||
fs.writeFileSync(dirName + "/TESTFILE", testString);
|
||||
|
||||
const dropletHandler = new DropletHandler();
|
||||
const stream = dropletHandler.readFile(dirName, "TESTFILE", BigInt(1), BigInt(4));
|
||||
const stream = dropletHandler.readFile(
|
||||
dirName,
|
||||
"TESTFILE",
|
||||
BigInt(1),
|
||||
BigInt(4)
|
||||
);
|
||||
|
||||
let finalString = "";
|
||||
|
||||
@ -96,37 +102,40 @@ test("read file offset", async (t) => {
|
||||
fs.rmSync(dirName, { recursive: true });
|
||||
});
|
||||
|
||||
test("zip file reader", async (t) => {
|
||||
return t.pass();
|
||||
|
||||
t.timeout(10_000);
|
||||
test("zip speed test", async (t) => {
|
||||
t.timeout(100_000_000);
|
||||
const dropletHandler = new DropletHandler();
|
||||
const manifest = JSON.parse(
|
||||
await new Promise((r, e) =>
|
||||
generateManifest(
|
||||
dropletHandler,
|
||||
"./assets/TheGame.zip",
|
||||
(_, __) => {},
|
||||
(_, __) => {},
|
||||
(err, manifest) => (err ? e(err) : r(manifest))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
const stream = dropletHandler.readFile(
|
||||
"./assets/TheGame.zip",
|
||||
"setup.exe",
|
||||
BigInt(10),
|
||||
BigInt(20)
|
||||
);
|
||||
const stream = dropletHandler.readFile("./assets/TheGame.zip", "setup.exe");
|
||||
|
||||
let totalRead = 0;
|
||||
let totalSeconds = 0;
|
||||
|
||||
let finalString = "";
|
||||
let lastTime = process.hrtime.bigint();
|
||||
const timeThreshold = BigInt(1_000_000_000);
|
||||
let runningTotal = 0;
|
||||
let runningTime = BigInt(0);
|
||||
for await (const chunk of stream.getStream()) {
|
||||
// Do something with each 'chunk'
|
||||
finalString = String.fromCharCode.apply(null, chunk);
|
||||
if(finalString.length > 100) break;
|
||||
const currentTime = process.hrtime.bigint();
|
||||
const timeDiff = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
runningTime += timeDiff;
|
||||
|
||||
runningTotal += chunk.length;
|
||||
|
||||
if (runningTime >= timeThreshold) {
|
||||
console.log(`${prettyBytes(runningTotal)}/s`);
|
||||
totalRead += runningTotal;
|
||||
totalSeconds += 1;
|
||||
runningTime = BigInt(0);
|
||||
runningTotal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const roughAverage = totalRead / totalSeconds;
|
||||
|
||||
console.log(`total rough average: ${prettyBytes(roughAverage)}/s`)
|
||||
|
||||
t.pass();
|
||||
});
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
yes "droplet is awesome" | dd of=./setup.exe bs=1024 count=1000000
|
||||
# yes "droplet is awesome" | dd of=./setup.exe bs=1024 count=1000000
|
||||
dd if=/dev/random of=./setup.exe bs=1024 count=1000000
|
||||
zip TheGame.zip setup.exe
|
||||
rm setup.exe
|
||||
@ -24,7 +24,9 @@
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "3.0.0-alpha.91",
|
||||
"@types/node": "^22.13.10",
|
||||
"ava": "^6.2.0"
|
||||
"ava": "^6.2.0",
|
||||
"pretty-bytes": "^7.0.1",
|
||||
"tsimp": "^2.0.12"
|
||||
},
|
||||
"ava": {
|
||||
"timeout": "3m",
|
||||
@ -51,8 +53,5 @@
|
||||
"packageManager": "yarn@4.7.0",
|
||||
"repository": {
|
||||
"url": "git+https://github.com/Drop-OSS/droplet.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsimp": "^2.0.12"
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ __metadata:
|
||||
"@napi-rs/cli": "npm:3.0.0-alpha.91"
|
||||
"@types/node": "npm:^22.13.10"
|
||||
ava: "npm:^6.2.0"
|
||||
pretty-bytes: "npm:^7.0.1"
|
||||
tsimp: "npm:^2.0.12"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@ -2432,6 +2433,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pretty-bytes@npm:^7.0.1":
|
||||
version: 7.0.1
|
||||
resolution: "pretty-bytes@npm:7.0.1"
|
||||
checksum: 10c0/14ffb503d2de3588042c722848062a4897e6faece1694e0c83ba5669ec003d73311d946d50d2b3c6099a6a306760011b8446ee3cf9cf86eca13a454a8f1c47cb
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pretty-ms@npm:^9.1.0":
|
||||
version: 9.2.0
|
||||
resolution: "pretty-ms@npm:9.2.0"
|
||||
|
||||
Reference in New Issue
Block a user