@@ -5,12 +5,12 @@ const { inherits, format } = require('node:util')
5
5
6
6
const fp = require ( 'fastify-plugin' )
7
7
const encodingNegotiator = require ( '@fastify/accept-negotiator' )
8
- const pump = require ( 'pump' )
9
8
const mimedb = require ( 'mime-db' )
10
9
const peek = require ( 'peek-stream' )
11
10
const { Minipass } = require ( 'minipass' )
12
11
const pumpify = require ( 'pumpify' )
13
12
const { Readable } = require ( 'readable-stream' )
13
+ const { pipeline } = require ( 'node:stream' )
14
14
15
15
const { isStream, isGzip, isDeflate, intoAsyncIterator } = require ( './lib/utils' )
16
16
@@ -267,15 +267,12 @@ function buildRouteCompress (fastify, params, routeOptions, decorateOnly) {
267
267
encoding === undefined
268
268
? reply . removeHeader ( 'Content-Encoding' )
269
269
: reply . header ( 'Content-Encoding' , 'identity' )
270
- pump ( stream , payload = unzipStream ( params . uncompressStream ) , onEnd . bind ( reply ) )
270
+ pipeline ( stream , payload = unzipStream ( params . uncompressStream ) , onEnd . bind ( reply ) )
271
271
}
272
272
return next ( null , payload )
273
273
}
274
- if ( payload instanceof ReadableStream ) {
275
- payload = require ( 'node:stream' ) . Readable . fromWeb ( payload )
276
- }
277
274
278
- if ( typeof payload . pipe !== 'function' ) {
275
+ if ( typeof payload . pipe !== 'function' && ! ( payload instanceof ReadableStream ) ) {
279
276
if ( Buffer . byteLength ( payload ) < params . threshold ) {
280
277
return next ( )
281
278
}
@@ -289,7 +286,7 @@ function buildRouteCompress (fastify, params, routeOptions, decorateOnly) {
289
286
}
290
287
291
288
stream = zipStream ( params . compressStream , encoding )
292
- pump ( payload , stream , onEnd . bind ( reply ) )
289
+ pipeline ( payload , stream , onEnd . bind ( reply ) )
293
290
next ( null , stream )
294
291
}
295
292
}
@@ -351,7 +348,7 @@ function buildRouteDecompress (fastify, params, routeOptions) {
351
348
raw . on ( 'data' , trackEncodedLength . bind ( decompresser ) )
352
349
raw . on ( 'end' , removeEncodedLengthTracking )
353
350
354
- next ( null , pump ( raw , decompresser ) )
351
+ next ( null , pipeline ( raw , decompresser ) )
355
352
}
356
353
}
357
354
@@ -388,22 +385,17 @@ function compress (params) {
388
385
encoding === undefined
389
386
? this . removeHeader ( 'Content-Encoding' )
390
387
: this . header ( 'Content-Encoding' , 'identity' )
391
- pump ( stream , payload = unzipStream ( params . uncompressStream ) , onEnd . bind ( this ) )
388
+ pipeline ( stream , payload = unzipStream ( params . uncompressStream ) , onEnd . bind ( this ) )
392
389
}
393
390
return this . send ( payload )
394
391
}
395
392
396
- if ( payload instanceof ReadableStream ) {
397
- payload = require ( 'node:stream' ) . Readable . fromWeb ( payload )
398
- }
393
+ if ( typeof payload . pipe !== 'function' && ! ( payload instanceof ReadableStream ) ) {
399
394
400
- if ( typeof payload . pipe !== 'function' ) {
401
395
if ( ! Buffer . isBuffer ( payload ) && typeof payload !== 'string' ) {
402
396
payload = this . serialize ( payload )
403
397
}
404
- }
405
398
406
- if ( typeof payload . pipe !== 'function' ) {
407
399
if ( Buffer . byteLength ( payload ) < params . threshold ) {
408
400
return this . send ( payload )
409
401
}
@@ -417,7 +409,7 @@ function compress (params) {
417
409
}
418
410
419
411
stream = zipStream ( params . compressStream , encoding )
420
- pump ( payload , stream , onEnd . bind ( this ) )
412
+ pipeline ( payload , stream , onEnd . bind ( this ) )
421
413
this . send ( stream )
422
414
}
423
415
}
0 commit comments