File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ unreleased
6
6
- deps: mime-db@'>= 1.38.0 < 2'
7
7
* deps: on-headers@~ 1.0.2
8
8
- Fix ` res.writeHead ` patch missing return value
9
+ * perf: prevent unnecessary buffer copy
9
10
10
11
1.7.3 / 2018-07-15
11
12
==================
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ function compression (options) {
85
85
}
86
86
87
87
return stream
88
- ? stream . write ( Buffer . from ( chunk , encoding ) )
88
+ ? stream . write ( toBuffer ( chunk , encoding ) )
89
89
: _write . call ( this , chunk , encoding )
90
90
}
91
91
@@ -112,7 +112,7 @@ function compression (options) {
112
112
113
113
// write Buffer for Node.js 0.8
114
114
return chunk
115
- ? stream . end ( Buffer . from ( chunk , encoding ) )
115
+ ? stream . end ( toBuffer ( chunk , encoding ) )
116
116
: stream . end ( )
117
117
}
118
118
@@ -275,3 +275,14 @@ function shouldTransform (req, res) {
275
275
return ! cacheControl ||
276
276
! cacheControlNoTransformRegExp . test ( cacheControl )
277
277
}
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