File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -68,4 +68,26 @@ describe("Brotli-wasm", () => {
68
68
) . toString ( 'utf8' ) ;
69
69
expect ( result ) . to . equal ( input ) ;
70
70
} ) ;
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
+ } ) ;
71
93
} ) ;
You can’t perform that action at this time.
0 commit comments