mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-13 00:02:46 +10:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd30464a08 |
@ -1,6 +1,7 @@
|
|||||||
import test from "ava";
|
import test from "ava";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { createHash } from "node:crypto";
|
||||||
import prettyBytes from "pretty-bytes";
|
import prettyBytes from "pretty-bytes";
|
||||||
|
|
||||||
import droplet, { DropletHandler, generateManifest } from "../index.js";
|
import droplet, { DropletHandler, generateManifest } from "../index.js";
|
||||||
@ -57,7 +58,12 @@ test("read file", async (t) => {
|
|||||||
|
|
||||||
const dropletHandler = new DropletHandler();
|
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 = "";
|
let finalString = "";
|
||||||
|
|
||||||
@ -157,6 +163,7 @@ test.skip("zip manifest test", async (t) => {
|
|||||||
for (const [filename, data] of Object.entries(manifest)) {
|
for (const [filename, data] of Object.entries(manifest)) {
|
||||||
let start = 0;
|
let start = 0;
|
||||||
for (const [chunkIndex, length] of data.lengths.entries()) {
|
for (const [chunkIndex, length] of data.lengths.entries()) {
|
||||||
|
const hash = createHash("md5");
|
||||||
const stream = (
|
const stream = (
|
||||||
await dropletHandler.readFile(
|
await dropletHandler.readFile(
|
||||||
"./assets/TheGame.zip",
|
"./assets/TheGame.zip",
|
||||||
@ -171,6 +178,7 @@ test.skip("zip manifest test", async (t) => {
|
|||||||
new WritableStream({
|
new WritableStream({
|
||||||
write(chunk) {
|
write(chunk) {
|
||||||
streamLength += chunk.length;
|
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}`
|
`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;
|
start += length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@drop-oss/droplet",
|
"name": "@drop-oss/droplet",
|
||||||
"version": "2.2.1",
|
"version": "2.3.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"napi": {
|
"napi": {
|
||||||
|
|||||||
@ -80,17 +80,17 @@ pub fn generate_manifest<'a>(
|
|||||||
|
|
||||||
length += read;
|
length += read;
|
||||||
|
|
||||||
if length >= CHUNK_SIZE {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're out of data, add this chunk and then move onto the next file
|
// If we're out of data, add this chunk and then move onto the next file
|
||||||
if read == 0 {
|
if read == 0 {
|
||||||
file_empty = true;
|
file_empty = true;
|
||||||
break;
|
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();
|
let chunk_id = Uuid::new_v4();
|
||||||
|
|||||||
Reference in New Issue
Block a user