Only call getFileStream callback once

This commit is contained in:
James Allen 2015-02-26 11:32:05 +00:00
parent eb40dbbe96
commit 45689fd2b8

View file

@ -27,7 +27,10 @@ module.exports =
return callback err
@sendFile location, target, fsPath, callback
getFileStream: (location, name, callback = (err, res)->)->
getFileStream: (location, name, _callback = (err, res)->) ->
callback = (args...) ->
_callback(args...)
_callback = () ->
filteredName = filterName name
logger.log location:location, name:filteredName, "getting file"
sourceStream = fs.createReadStream "#{location}/#{filteredName}"
@ -38,6 +41,8 @@ module.exports =
else
callback err
sourceStream.on 'readable', () ->
# This can be called multiple times, but the callback wrapper
# ensures the callback is only called once
callback null, sourceStream