File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ unreleased
66 - deps: mime-db@'>= 1.38.0 < 2'
77 * deps: on-headers@~ 1.0.2
88 - Fix ` res.writeHead ` patch missing return value
9+ * perf: prevent unnecessary buffer copy
910
10111.7.3 / 2018-07-15
1112==================
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ function compression (options) {
8585 }
8686
8787 return stream
88- ? stream . write ( Buffer . from ( chunk , encoding ) )
88+ ? stream . write ( toBuffer ( chunk , encoding ) )
8989 : _write . call ( this , chunk , encoding )
9090 }
9191
@@ -112,7 +112,7 @@ function compression (options) {
112112
113113 // write Buffer for Node.js 0.8
114114 return chunk
115- ? stream . end ( Buffer . from ( chunk , encoding ) )
115+ ? stream . end ( toBuffer ( chunk , encoding ) )
116116 : stream . end ( )
117117 }
118118
@@ -275,3 +275,14 @@ function shouldTransform (req, res) {
275275 return ! cacheControl ||
276276 ! cacheControlNoTransformRegExp . test ( cacheControl )
277277}
278+
279+ /**
280+ * Coerce arguments to Buffer
281+ * @private
282+ */
283+
284+ function toBuffer ( chunk , encoding ) {
285+ return ! Buffer . isBuffer ( chunk )
286+ ? Buffer . from ( chunk , encoding )
287+ : chunk
288+ }
You can’t perform that action at this time.
0 commit comments