@@ -191,15 +191,14 @@ describe("Brotli-wasm", () => {
191
191
expect ( decOutput . toString ( 'utf8' ) ) . to . equal ( s ) ;
192
192
} ) ;
193
193
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 ) ;
199
198
const stream = new brotli . CompressStream ( ) ;
200
199
const output1 = stream . compress ( input , 1 ) ;
201
200
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 ) ;
203
202
expect ( stream . result ( ) ) . to . equal ( brotli . BrotliStreamResult . NeedsMoreInput ) ;
204
203
const output3 = stream . compress ( undefined , 1640000 ) ;
205
204
expect ( stream . result ( ) ) . to . equal ( brotli . BrotliStreamResult . ResultSuccess ) ;
@@ -217,3 +216,19 @@ describe("Brotli-wasm", () => {
217
216
expect ( Buffer . concat ( [ output1 , output2 ] ) . toString ( 'utf8' ) ) . to . equal ( 'Brotli brotli brotli brotli' ) ;
218
217
} ) ;
219
218
} ) ;
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