Skip to content

Commit 47b69b3

Browse files
only invoke callback once
1 parent 51d71c1 commit 47b69b3

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/storage/file.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var crc = require('fast-crc32c');
2626
var crypto = require('crypto');
2727
var duplexify = require('duplexify');
2828
var fs = require('fs');
29+
var once = require('node-once');
2930
var request = require('request');
3031
var streamEvents = require('stream-events');
3132
var through = require('through2');
@@ -649,6 +650,8 @@ File.prototype.download = function(options, callback) {
649650
options = {};
650651
}
651652

653+
callback = once(callback);
654+
652655
var destination = options.destination;
653656
delete options.destination;
654657

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"fast-crc32c": "^0.1.3",
5252
"google-service-account": "^1.0.3",
5353
"mime-types": "^2.0.3",
54+
"node-once": "0.0.1",
5455
"node-uuid": "^1.4.1",
5556
"protobufjs": "^3.4.0",
5657
"request": "^2.39.0",

test/storage/file.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,17 @@ describe('File', function() {
787787
file.download(readOptions, assert.ifError);
788788
});
789789

790+
it('should only execute callback once', function(done) {
791+
fileReadStream._read = function() {
792+
this.emit('error', new Error('Error.'));
793+
this.emit('error', new Error('Error.'));
794+
};
795+
796+
file.download(function() {
797+
done();
798+
});
799+
});
800+
790801
describe('into memory', function() {
791802
it('should buffer a file into memory if no destination', function(done) {
792803
var fileContents = 'abcdefghijklmnopqrstuvwxyz';

0 commit comments

Comments
 (0)