Skip to content

Commit

Permalink
Minimizing ops in res.send()
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Jul 2, 2018
1 parent 04f69a6 commit 4399f51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class Woodland extends Base {

partial(req, res, buffered, status, headers);
output = buffered.slice(req.range.start, req.range.end + 1).toString();
} else if (typeof output !== "string") {
output = "toString" in output ? output.toString() : output;
} else if (typeof output !== "string" && "toString" in output) {
output = output.toString();
}
}

Expand All @@ -109,7 +109,9 @@ class Woodland extends Base {
writeHead(res, status, headers);
output.on("error", () => void 0).pipe(res);
} else {
output = typeof output === "string" ? output : "toString" in output ? output.toString() : output;
if (typeof output !== "string" && "toString" in output) {
output = output.toString();
}

if (req.headers.range !== void 0) {
const buffered = Buffer.from(output);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woodland",
"version": "7.1.2",
"version": "7.1.3",
"description": "Lightweight HTTP/HTTP2 router with automatic `Allow` & `CORS` headers",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4399f51

Please sign in to comment.