@@ -5,7 +5,11 @@ const expect = chai.expect;
55
66import {
77 createGzipStream ,
8- createGunzipStream
8+ createGunzipStream ,
9+ createDeflateStream ,
10+ createInflateStream ,
11+ createDeflateRawStream ,
12+ createInflateRawStream
913} from '../src/index' ;
1014
1115// Helper to collect all chunks from a ReadableStream into a single Uint8Array
@@ -121,4 +125,76 @@ describe("Streaming", () => {
121125 expect ( decompressed . toString ( ) ) . to . equal ( repeated ) ;
122126 } ) ;
123127 } ) ;
128+
129+ describe ( "Deflate" , ( ) => {
130+ it ( 'should compress data with deflate stream' , async ( ) => {
131+ const input = Buffer . from ( 'Hello streaming deflate world!' ) ;
132+ const inputStream = createReadableStream ( input ) ;
133+
134+ const compressedStream = inputStream . pipeThrough ( createDeflateStream ( ) ) ;
135+ const compressed = await collectStream ( compressedStream ) ;
136+
137+ // Verify the compressed data can be decompressed with zlib
138+ const decompressed = zlib . inflateSync ( Buffer . from ( compressed ) ) ;
139+ expect ( decompressed . toString ( ) ) . to . equal ( 'Hello streaming deflate world!' ) ;
140+ } ) ;
141+
142+ it ( 'should decompress deflate data with stream' , async ( ) => {
143+ const original = 'Hello streaming inflate world!' ;
144+ const compressed = zlib . deflateSync ( original ) ;
145+ const inputStream = createReadableStream ( compressed ) ;
146+
147+ const decompressedStream = inputStream . pipeThrough ( createInflateStream ( ) ) ;
148+ const decompressed = await collectStream ( decompressedStream ) ;
149+
150+ expect ( Buffer . from ( decompressed ) . toString ( ) ) . to . equal ( original ) ;
151+ } ) ;
152+
153+ it ( 'should handle round-trip compression and decompression' , async ( ) => {
154+ const original = 'Round-trip deflate streaming test with some repeated data data data data' ;
155+ const inputStream = createReadableStream ( Buffer . from ( original ) ) ;
156+
157+ const compressedStream = inputStream . pipeThrough ( createDeflateStream ( ) ) ;
158+ const decompressedStream = compressedStream . pipeThrough ( createInflateStream ( ) ) ;
159+ const result = await collectStream ( decompressedStream ) ;
160+
161+ expect ( Buffer . from ( result ) . toString ( ) ) . to . equal ( original ) ;
162+ } ) ;
163+ } ) ;
164+
165+ describe ( "Deflate-Raw" , ( ) => {
166+ it ( 'should compress data with deflate-raw stream' , async ( ) => {
167+ const input = Buffer . from ( 'Hello streaming deflate-raw world!' ) ;
168+ const inputStream = createReadableStream ( input ) ;
169+
170+ const compressedStream = inputStream . pipeThrough ( createDeflateRawStream ( ) ) ;
171+ const compressed = await collectStream ( compressedStream ) ;
172+
173+ // Verify the compressed data can be decompressed with zlib
174+ const decompressed = zlib . inflateRawSync ( Buffer . from ( compressed ) ) ;
175+ expect ( decompressed . toString ( ) ) . to . equal ( 'Hello streaming deflate-raw world!' ) ;
176+ } ) ;
177+
178+ it ( 'should decompress deflate-raw data with stream' , async ( ) => {
179+ const original = 'Hello streaming inflate-raw world!' ;
180+ const compressed = zlib . deflateRawSync ( original ) ;
181+ const inputStream = createReadableStream ( compressed ) ;
182+
183+ const decompressedStream = inputStream . pipeThrough ( createInflateRawStream ( ) ) ;
184+ const decompressed = await collectStream ( decompressedStream ) ;
185+
186+ expect ( Buffer . from ( decompressed ) . toString ( ) ) . to . equal ( original ) ;
187+ } ) ;
188+
189+ it ( 'should handle round-trip compression and decompression' , async ( ) => {
190+ const original = 'Round-trip deflate-raw streaming test with some repeated data data data data' ;
191+ const inputStream = createReadableStream ( Buffer . from ( original ) ) ;
192+
193+ const compressedStream = inputStream . pipeThrough ( createDeflateRawStream ( ) ) ;
194+ const decompressedStream = compressedStream . pipeThrough ( createInflateRawStream ( ) ) ;
195+ const result = await collectStream ( decompressedStream ) ;
196+
197+ expect ( Buffer . from ( result ) . toString ( ) ) . to . equal ( original ) ;
198+ } ) ;
199+ } ) ;
124200} ) ;
0 commit comments