2 Commits

Author SHA1 Message Date
bd30464a08 fix: manifest generation with multiple chunks 2025-08-15 21:56:33 +10:00
c67cca4ee0 fix: remove debug println 2025-08-15 21:41:48 +10:00
3 changed files with 21 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import test from "ava";
import fs from "node:fs";
import path from "path";
import { createHash } from "node:crypto";
import prettyBytes from "pretty-bytes";
import droplet, { DropletHandler, generateManifest } from "../index.js";
@ -57,7 +58,12 @@ test("read file", async (t) => {
const dropletHandler = new DropletHandler();
const stream = dropletHandler.readFile(dirName, "TESTFILE", BigInt(0), BigInt(testString.length));
const stream = dropletHandler.readFile(
dirName,
"TESTFILE",
BigInt(0),
BigInt(testString.length)
);
let finalString = "";
@ -157,6 +163,7 @@ test.skip("zip manifest test", async (t) => {
for (const [filename, data] of Object.entries(manifest)) {
let start = 0;
for (const [chunkIndex, length] of data.lengths.entries()) {
const hash = createHash("md5");
const stream = (
await dropletHandler.readFile(
"./assets/TheGame.zip",
@ -171,6 +178,7 @@ test.skip("zip manifest test", async (t) => {
new WritableStream({
write(chunk) {
streamLength += chunk.length;
hash.update(chunk);
},
})
);
@ -180,6 +188,12 @@ test.skip("zip manifest test", async (t) => {
`stream length for chunk index ${chunkIndex} was not expected: real: ${streamLength} vs expected: ${length}`
);
const digest = hash.digest("hex");
if (data.checksums[chunkIndex] != digest)
return t.fail(
`checksums did not match for chunk index ${chunkIndex}: real: ${digest} vs expected: ${data.checksums[chunkIndex]}`
);
start += length;
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@drop-oss/droplet",
"version": "2.2.0",
"version": "2.3.0",
"main": "index.js",
"types": "index.d.ts",
"napi": {

View File

@ -80,20 +80,18 @@ pub fn generate_manifest<'a>(
length += read;
if length >= CHUNK_SIZE {
break;
}
// If we're out of data, add this chunk and then move onto the next file
if read == 0 {
file_empty = true;
break;
}
buffer.extend_from_slice(&buf[..read]);
}
buffer.extend_from_slice(&buf[0..read]);
println!("created chunk of size {}", length);
if length >= CHUNK_SIZE {
break;
}
}
let chunk_id = Uuid::new_v4();
let checksum = md5::compute(buffer).0;