Skip to content

Commit

Permalink
fix finish event on createWriteStream.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Aug 20, 2017
1 parent 936b13f commit 370a015
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"awestruct": "^0.12.1",
"blob-to-buffer": "^1.2.6",
"from2-blob": "^1.0.0",
"from2-blob": "^1.0.1",
"from2-buffer": "^1.0.0",
"is-buffer": "^1.1.5",
"multistream": "^2.1.0",
Expand Down
16 changes: 9 additions & 7 deletions src/DRS.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,21 @@ DRS.prototype.createWriteStream = function (type, id) {
var table = getTable(this, type)

var data = []
var cb = createFileBufferCallback(file, table, onfinish)
var stream = to(function (chunk, enc, next) {
data.push(chunk)
next()
}, function (next) {
var cb = createFileBufferCallback(file, table, onfinish)
cb(null, Buffer.concat(data))
next()
})

function onfinish (err, file) {
if (err) stream.emit('error', err)
else stream.emit('meta', file)
}
function onfinish (err, file) {
if (!err) {
stream.emit('meta', file)
}

next(err)
}
})

return stream
}
Expand Down

0 comments on commit 370a015

Please sign in to comment.