Skip to content

Commit e295a2d

Browse files
committed
check sha of edited file
1 parent 4615e00 commit e295a2d

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

packages/hub/scripts/bench.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { join } from "node:path";
66
import { writeFile, readFile, stat, mkdir } from "node:fs/promises";
77
import type { RepoId } from "../src/types/public.js";
88
import { toRepoId } from "../src/utils/toRepoId.js";
9-
import { commitIter } from "../src/index.js";
10-
import { pathToFileURL } from "node:url";
9+
import type { CommitOperation } from "../src/index.js";
10+
import { commitIter, downloadFile } from "../src/index.js";
1111
import { WebBlob } from "../src/utils/WebBlob.js";
1212
import { SplicedBlob } from "../src/utils/SplicedBlob.js";
13+
import { pathToFileURL } from "node:url";
1314

1415
/**
1516
* This script downloads the files from openai-community/gpt2 and simulates an upload to a xet repo.
@@ -337,13 +338,25 @@ async function main() {
337338

338339
if (args.commit) {
339340
console.log("\n=== Committing files ===");
341+
const operations: CommitOperation[] = [];
342+
for (const fileInfo of FILES_TO_DOWNLOAD) {
343+
operations.push({
344+
operation: "addOrUpdate",
345+
content: pathToFileURL(join(downloadDir, fileInfo.filename)),
346+
path: fileInfo.filename,
347+
});
348+
}
349+
for (const fileInfo of FILES_TO_EDIT) {
350+
operations.push({
351+
operation: "edit",
352+
originalContent: new Blob([await readFile(join(downloadDir, fileInfo.filename))]),
353+
edits: fileInfo.edits,
354+
path: fileInfo.filename,
355+
});
356+
}
340357
const iterator = commitIter({
341358
repo,
342-
operations: files.map((file) => ({
343-
operation: "addOrUpdate",
344-
content: pathToFileURL(file.filepath),
345-
path: file.filename,
346-
})),
359+
operations,
347360
accessToken: args.token,
348361
title: "Upload xet files with JS lib",
349362
useXet: true,
@@ -360,7 +373,16 @@ async function main() {
360373

361374
console.log("Redownloading files and verifying SHA256 integrity");
362375
for (const file of FILES_TO_DOWNLOAD) {
363-
const fileBlob = await WebBlob.create(new URL(file.url));
376+
const fileBlob = await downloadFile({
377+
repo,
378+
path: file.filename,
379+
accessToken: args.token,
380+
});
381+
382+
if (!fileBlob) {
383+
throw new Error(`Failed to download ${file.filename}`);
384+
}
385+
364386
const sha256Hash = sha256(fileBlob, { useWebWorker: false });
365387
let res: IteratorResult<number, string>;
366388
do {
@@ -372,7 +394,16 @@ async function main() {
372394
}
373395

374396
for (const file of FILES_TO_EDIT) {
375-
const fileBlob = await WebBlob.create(new URL(file.url));
397+
const fileBlob = await downloadFile({
398+
repo,
399+
path: file.filename,
400+
accessToken: args.token,
401+
});
402+
403+
if (!fileBlob) {
404+
throw new Error(`Failed to download ${file.filename}`);
405+
}
406+
376407
const sha256Hash = sha256(fileBlob, { useWebWorker: false });
377408
let res: IteratorResult<number, string>;
378409
do {

0 commit comments

Comments
 (0)