Skip to content

Commit 62da886

Browse files
committed
Re-enable streaming compressing needing more output test
Generate random data in code other than reading fixture file
1 parent a1192ae commit 62da886

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

test/brotli.spec.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,14 @@ describe("Brotli-wasm", () => {
191191
expect(decOutput.toString('utf8')).to.equal(s);
192192
});
193193

194-
it("streaming compressing can handle needing more output", () => {
195-
// Suppressed currently since it requires a large file as input
196-
return;
197-
// const input = fs.readFileSync('test/encLongInput.bin');
198-
const input = Buffer.from("test");
194+
it("streaming compressing can handle needing more output when action is process", () => {
195+
// The input should be more than about 1.6MB with enough randomness
196+
// to make the compressor ask for more output space when the action is PROCESS
197+
const input = genRandBytes(1600000);
199198
const stream = new brotli.CompressStream();
200199
const output1 = stream.compress(input, 1);
201200
expect(stream.result()).to.equal(brotli.BrotliStreamResult.NeedsMoreOutput);
202-
const output2 = stream.compress(input.slice(stream.last_input_offset()), 1640000);
201+
const output2 = stream.compress(input.slice(stream.last_input_offset()), 1500000);
203202
expect(stream.result()).to.equal(brotli.BrotliStreamResult.NeedsMoreInput);
204203
const output3 = stream.compress(undefined, 1640000);
205204
expect(stream.result()).to.equal(brotli.BrotliStreamResult.ResultSuccess);
@@ -217,3 +216,19 @@ describe("Brotli-wasm", () => {
217216
expect(Buffer.concat([output1, output2]).toString('utf8')).to.equal('Brotli brotli brotli brotli');
218217
});
219218
});
219+
220+
/**
221+
* Generate random bytes for tests
222+
* @param size Must be a multiple of 4
223+
*/
224+
function genRandBytes(size: number) {
225+
const buf = [] as number[];
226+
for (let i = 0; i < size / 4; i++) {
227+
const rand = Math.floor(Math.random() * Math.pow(2, 32));
228+
buf.push((rand >> 0) & 0xff);
229+
buf.push((rand >> 8) & 0xff);
230+
buf.push((rand >> 16) & 0xff);
231+
buf.push((rand >> 24) & 0xff);
232+
}
233+
return Buffer.from(buf);
234+
}

0 commit comments

Comments
 (0)