Skip to content

Commit aee1a65

Browse files
committed
1 parent 6060bda commit aee1a65

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

HISTORY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ unreleased
55
66
- Replace internal `eval` usage with `Function` constructor
77
- Use instance methods on `process` to check for listeners
8-
* deps: destroy@1.1.1
8+
* deps: destroy@1.2.0
99
1010
1111

index.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,6 @@ SendStream.prototype.sendIndex = function sendIndex (path) {
785785
*/
786786

787787
SendStream.prototype.stream = function stream (path, options) {
788-
// TODO: this is all lame, refactor meeee
789-
var finished = false
790788
var self = this
791789
var res = this.res
792790

@@ -795,20 +793,18 @@ SendStream.prototype.stream = function stream (path, options) {
795793
this.emit('stream', stream)
796794
stream.pipe(res)
797795

798-
// response finished, done with the fd
799-
onFinished(res, function onfinished () {
800-
finished = true
801-
destroy(stream)
802-
})
796+
// cleanup
797+
function cleanup () {
798+
destroy(stream, true)
799+
}
803800

804-
// error handling code-smell
805-
stream.on('error', function onerror (err) {
806-
// request already finished
807-
if (finished) return
801+
// response finished, cleanup
802+
onFinished(res, cleanup)
808803

809-
// clean up stream
810-
finished = true
811-
destroy(stream)
804+
// error handling
805+
stream.on('error', function onerror (err) {
806+
// clean up stream early
807+
cleanup()
812808

813809
// error
814810
self.onStatError(err)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"debug": "2.6.9",
2020
"depd": "2.0.0",
21-
"destroy": "1.1.1",
21+
"destroy": "1.2.0",
2222
"encodeurl": "~1.0.2",
2323
"escape-html": "~1.0.3",
2424
"etag": "~1.8.1",

0 commit comments

Comments
 (0)