Skip to content

Commit 634562a

Browse files
committed
Add basic tests for decompressing
1 parent 9463a11 commit 634562a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/brotli.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,26 @@ describe("Brotli-wasm", () => {
6868
).toString('utf8');
6969
expect(result).to.equal(input);
7070
});
71+
72+
it("can streamingly decompress data", () => {
73+
// Generated with: echo -n '$CONTENT' | brotli --stdout - | base64
74+
const input = Buffer.from('GxoAABypU587dC0k9ianQOgqjS32iUTcCA==', 'base64');
75+
const input1 = input.slice(0, input.length / 2);
76+
const input2 = input.slice(input.length / 2);
77+
const stream = new brotli.DecompressStream();
78+
const output1 = stream.decompress(input1, 100);
79+
expect(stream.result()).to.equal(brotli.BrotliStreamResult.NeedsMoreInput);
80+
const output2 = stream.decompress(input2, 100);
81+
expect(stream.result()).to.equal(brotli.BrotliStreamResult.ResultSuccess);
82+
expect(Buffer.concat([output1, output2]).toString('utf8')).to.equal('Brotli brotli brotli brotli');
83+
});
84+
85+
it("cleanly fails when streamingly decompressing garbage", () => {
86+
const input = Buffer.from("This is not brotli data, it's just a string");
87+
const stream = new brotli.DecompressStream();
88+
expect(() =>
89+
stream.decompress(input, 100)
90+
).to.throw('Brotli streaming decompress failed');
91+
expect(stream.result()).to.lt(0);
92+
});
7193
});

0 commit comments

Comments
 (0)