Closed
Description
I think there is an error in this function (storage/file.js):
File.prototype.download = function(options, callback) {
if (util.is(options, 'function')) {
callback = options;
options = {};
}
callback = once(callback);
var destination = options.destination;
delete options.destination;
var fileStream = this.createReadStream(options);
if (destination) {
fileStream
.on('error', callback)
.pipe(fs.createWriteStream(destination))
.on('error', callback)
.on('finish', callback);
} else {
var fileContents = new Buffer('');
fileStream
.on('error', callback)
.on('data', function(chunk) {
fileContents = Buffer.concat([fileContents, chunk]);
})
.on('complete', function() {
callback(null, fileContents);
});
}
};
I dont use the destination option, and the function works, but if I have multiple requests to the same file. Then somtimes the download is pending and never returns anything...
I don't know if it is the once(callback) because it is the same callback for multiple requests but this is strange, I replaced the function with my own code and now it is working:
var iStream = file.gFile.createReadStream();
var fileData = new Buffer('');
iStream.on('error', function(err){
Log.error(err);
loadCB(null);
});
iStream.on('data', function(data){
fileData = Buffer.concat([fileData, data]);
});
iStream.on('complete', function() {
loadCB(fileData);
});