Explorar el Código

Only call getFileStream callback once

James Allen hace 11 años
padre
commit
45689fd2b8
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      services/filestore/app/coffee/FSPersistorManager.coffee

+ 6 - 1
services/filestore/app/coffee/FSPersistorManager.coffee

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