|
| 1 | +'use strict'; |
| 2 | +require('../common'); |
| 3 | +constassert=require('assert').strict; |
| 4 | +consttest=require('node:test'); |
| 5 | +const{ DecompressionStream }=require('stream/web'); |
| 6 | + |
| 7 | +asyncfunctionexpectTypeError(promise){ |
| 8 | +letthrew=false; |
| 9 | +try{ |
| 10 | +awaitpromise; |
| 11 | +}catch(err){ |
| 12 | +threw=true; |
| 13 | +assert(errinstanceofTypeError,`Expected TypeError, got ${err}`); |
| 14 | +} |
| 15 | +assert(threw,'Expected promise to reject'); |
| 16 | +} |
| 17 | + |
| 18 | +test('DecompressStream deflat emits error on trailing data',async()=>{ |
| 19 | +constvalid=newUint8Array([120,156,75,4,0,0,98,0,98]);// deflate('a') |
| 20 | +constempty=newUint8Array(1); |
| 21 | +constinvalid=newUint8Array([...valid, ...empty]); |
| 22 | +constdouble=newUint8Array([...valid, ...valid]); |
| 23 | + |
| 24 | +for(constchunkof[[invalid],[valid,empty],[valid,valid],[valid,double]]){ |
| 25 | +awaitexpectTypeError( |
| 26 | +Array.fromAsync( |
| 27 | +newBlob([chunk]).stream().pipeThrough(newDecompressionStream('deflate')) |
| 28 | +) |
| 29 | +); |
| 30 | +} |
| 31 | +}); |
| 32 | + |
| 33 | +test('DecompressStream gzip emits error on trailing data',async()=>{ |
| 34 | +constvalid=newUint8Array([31,139,8,0,0,0,0,0,0,19,75,4, |
| 35 | +0,67,190,183,232,1,0,0,0]);// gzip('a') |
| 36 | +constempty=newUint8Array(1); |
| 37 | +constinvalid=newUint8Array([...valid, ...empty]); |
| 38 | +constdouble=newUint8Array([...valid, ...valid]); |
| 39 | +for(constchunkof[[invalid],[valid,empty],[valid,valid],[double]]){ |
| 40 | +awaitexpectTypeError( |
| 41 | +Array.fromAsync( |
| 42 | +newBlob([chunk]).stream().pipeThrough(newDecompressionStream('gzip')) |
| 43 | +) |
| 44 | +); |
| 45 | +} |
| 46 | +}); |
0 commit comments