Skip to content

Commit

Permalink
Merge 0dafcad into ad5113b
Browse files Browse the repository at this point in the history
  • Loading branch information
Icehunter committed Jul 30, 2022
2 parents ad5113b + 0dafcad commit dacf5a9
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 166 deletions.
27 changes: 8 additions & 19 deletions index.js
Expand Up @@ -81,12 +81,10 @@ function compression (options) {
}

if (!this._header) {
this._implicitHeader()
this.writeHead(this.statusCode)
}

return stream
? stream.write(toBuffer(chunk, encoding))
: _write.call(this, chunk, encoding)
return stream ? stream.write(toBuffer(chunk, encoding)) : _write.call(this, chunk, encoding)
}

res.end = function end (chunk, encoding) {
Expand All @@ -100,7 +98,7 @@ function compression (options) {
length = chunkLength(chunk, encoding)
}

this._implicitHeader()
this.writeHead(this.statusCode)
}

if (!stream) {
Expand All @@ -111,9 +109,7 @@ function compression (options) {
ended = true

// write Buffer for Node.js 0.8
return chunk
? stream.end(toBuffer(chunk, encoding))
: stream.end()
return chunk ? stream.end(toBuffer(chunk, encoding)) : stream.end()
}

res.on = function on (type, listener) {
Expand Down Expand Up @@ -190,9 +186,7 @@ function compression (options) {

// compression stream
debug('%s compression', method)
stream = method === 'gzip'
? zlib.createGzip(opts)
: zlib.createDeflate(opts)
stream = method === 'gzip' ? zlib.createGzip(opts) : zlib.createDeflate(opts)

// add buffered listeners to stream
addListeners(stream, stream.on, listeners)
Expand Down Expand Up @@ -241,9 +235,7 @@ function chunkLength (chunk, encoding) {
return 0
}

return !Buffer.isBuffer(chunk)
? Buffer.byteLength(chunk, encoding)
: chunk.length
return !Buffer.isBuffer(chunk) ? Buffer.byteLength(chunk, encoding) : chunk.length
}

/**
Expand Down Expand Up @@ -272,8 +264,7 @@ function shouldTransform (req, res) {

// Don't compress for Cache-Control: no-transform
// https://tools.ietf.org/html/rfc7234#section-5.2.2.4
return !cacheControl ||
!cacheControlNoTransformRegExp.test(cacheControl)
return !cacheControl || !cacheControlNoTransformRegExp.test(cacheControl)
}

/**
Expand All @@ -282,7 +273,5 @@ function shouldTransform (req, res) {
*/

function toBuffer (chunk, encoding) {
return !Buffer.isBuffer(chunk)
? Buffer.from(chunk, encoding)
: chunk
return !Buffer.isBuffer(chunk) ? Buffer.from(chunk, encoding) : chunk
}

0 comments on commit dacf5a9

Please sign in to comment.