mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-10 04:22:16 +10:00
fix: manifest generation with multiple chunks
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@drop-oss/droplet",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.0",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"napi": {
|
||||
|
||||
@ -80,17 +80,17 @@ 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]);
|
||||
|
||||
if length >= CHUNK_SIZE {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let chunk_id = Uuid::new_v4();
|
||||
|
||||
Reference in New Issue
Block a user