Skip to content

Commit

Permalink
fix(gftp-server-adapter): fixed hash calculation for files larger tha…
Browse files Browse the repository at this point in the history
…n 2gb
  • Loading branch information
mgordel committed Aug 29, 2024
1 parent a3658cf commit 92ffba7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/shared/storage/GftpServerAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class GftpServerAdapter implements IFileServer {
}

const fileUrl = await this.storage.publishFile(sourcePath);
const fileHash = this.calculateFileHash(sourcePath);
const fileHash = await this.calculateFileHash(sourcePath);

const entry = {
fileUrl,
Expand All @@ -46,8 +46,14 @@ export class GftpServerAdapter implements IFileServer {
return this.published.has(sourcePath);
}

private calculateFileHash(localPath: string): string {
const fileBuffer = fs.readFileSync(localPath);
return jsSha3.sha3_224(fileBuffer);
private async calculateFileHash(localPath: string): Promise<string> {
const fileStream = fs.createReadStream(localPath);
const hash = jsSha3.sha3_224.create();

return new Promise((resolve, reject) => {
fileStream.on("data", (chunk: Buffer) => hash.update(chunk));
fileStream.on("end", () => resolve(hash.hex()));
fileStream.on("error", (err) => reject(new GolemInternalError(`Error calculating file hash: ${err}`, err)));
});
}
}

0 comments on commit 92ffba7

Please sign in to comment.