From aee1a657be9fdf558ce3448c6a908227e15f0645 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 20 Mar 2022 22:35:28 -0400 Subject: [PATCH] deps: destroy@1.2.0 --- HISTORY.md | 2 +- index.js | 24 ++++++++++-------------- package.json | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 37b0d3a..581fa89 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,7 +5,7 @@ unreleased * deps: depd@2.0.0 - Replace internal `eval` usage with `Function` constructor - Use instance methods on `process` to check for listeners - * deps: destroy@1.1.1 + * deps: destroy@1.2.0 * deps: http-errors@2.0.0 - deps: depd@2.0.0 - deps: statuses@2.0.1 diff --git a/index.js b/index.js index fbdecf3..5ba20d9 100644 --- a/index.js +++ b/index.js @@ -785,8 +785,6 @@ SendStream.prototype.sendIndex = function sendIndex (path) { */ SendStream.prototype.stream = function stream (path, options) { - // TODO: this is all lame, refactor meeee - var finished = false var self = this var res = this.res @@ -795,20 +793,18 @@ SendStream.prototype.stream = function stream (path, options) { this.emit('stream', stream) stream.pipe(res) - // response finished, done with the fd - onFinished(res, function onfinished () { - finished = true - destroy(stream) - }) + // cleanup + function cleanup () { + destroy(stream, true) + } - // error handling code-smell - stream.on('error', function onerror (err) { - // request already finished - if (finished) return + // response finished, cleanup + onFinished(res, cleanup) - // clean up stream - finished = true - destroy(stream) + // error handling + stream.on('error', function onerror (err) { + // clean up stream early + cleanup() // error self.onStatError(err) diff --git a/package.json b/package.json index 0a2bab3..98d1a75 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dependencies": { "debug": "2.6.9", "depd": "2.0.0", - "destroy": "1.1.1", + "destroy": "1.2.0", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "etag": "~1.8.1",