Skip to content

Commit

Permalink
fix: treehash on non-fractional MB (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Coalwell committed Mar 2, 2020
1 parent 7dceadb commit 27774b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/sha256-tree-hash/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ describe("ChecksumGenerator", () => {
);
});

it("computes tree hashes of bodies = 1 MB", async () => {
const treeHash = new TreeHash(Sha256, fromUtf8);
const payload = new Uint8Array(1024 * 1024);
payload.fill(0);

treeHash.update(payload);
let results = await treeHash.digest();

expect(toHex(results)).toEqual(
"30e14955ebf1352266dc2ff8067e68104607e750abb9d3b36582b8af909fcb58"
);
});

it("computes tree hashes of chunked bodies", async () => {
const treeHash = new TreeHash(Sha256, fromUtf8);
const payload = new Uint8Array(1024 * 1024 * 5.5);
Expand Down
2 changes: 1 addition & 1 deletion packages/sha256-tree-hash/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class TreeHash implements Hash {
this.collectedHashDigests = [];

// loop through collected hashes
if (this.buffer) {
if (this.buffer && this.buffer.byteLength > 0) {
const smallHash = new this.Sha256();
smallHash.update(this.buffer);
collectedHashDigests.push(smallHash.digest());
Expand Down

0 comments on commit 27774b5

Please sign in to comment.