Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/bigquery/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ Table.prototype.createWriteStream = function(metadata) {
job.metadata = data;

dup.emit('complete', job);
dup.end();
});
});

Expand Down
4 changes: 1 addition & 3 deletions lib/common/stream-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ streamRouter.runAsStream_ = function(parsedArguments, originalMethod) {

function onResultSet(err, results, nextQuery) {
if (err) {
stream.emit('error', err);
stream.end();
stream.destroy(err);
return;
}

Expand All @@ -206,7 +205,6 @@ streamRouter.runAsStream_ = function(parsedArguments, originalMethod) {
}

stream.push(null);
stream.end();
});
}

Expand Down
9 changes: 3 additions & 6 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ function makeWritableStream(dup, options, onComplete) {
options.makeAuthorizedRequest(reqOpts, {
onAuthorized: function(err, authorizedReqOpts) {
if (err) {
dup.emit('error', err);
dup.end();
dup.destroy(err);
return;
}

Expand Down Expand Up @@ -274,8 +273,7 @@ function makeWritableStream(dup, options, onComplete) {
stream.on('complete', function(res) {
util.handleResp(null, res, res.body, function(err, data) {
if (err) {
dup.emit('error', err);
dup.end();
dup.destroy(err);
return;
}
onComplete(data);
Expand Down Expand Up @@ -474,8 +472,7 @@ function makeAuthorizedRequestFactory(config) {
function onAuthorized(err, authorizedReqOpts) {
if (err) {
if (stream) {
stream.emit('error', err);
stream.end();
stream.destroy(err);
} else {
(options.onAuthorized || options)(err);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ DatastoreRequest.prototype.get = function(keys, callback) {

function onApiResponse(err, resp) {
if (err) {
stream.emit('error', err);
stream.end();
stream.destroy(err);
return;
}

Expand All @@ -186,7 +185,6 @@ DatastoreRequest.prototype.get = function(keys, callback) {
}

stream.push(null);
stream.end();
});
}

Expand Down
13 changes: 4 additions & 9 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,10 @@ File.prototype.createReadStream = function(options) {
var endThroughStream = once(function(err, resp) {
if (err) {
throughStream.emit('error', err, resp);
throughStream.destroy();
} else {
throughStream.emit('complete', resp);
}

throughStream.destroy();
});

makeAuthorizedReq(remoteFilePath);
Expand Down Expand Up @@ -788,8 +787,7 @@ File.prototype.createWriteStream = function(options) {

// Catch any errors from the writable stream and patch them upstream.
.on('error', function(err) {
throughStream.emit('error', err);
throughStream.end();
throughStream.destroy(err);
})

// Compare our hashed version vs the completed upload's version.
Expand Down Expand Up @@ -840,13 +838,11 @@ File.prototype.createWriteStream = function(options) {
error.code = code;
error.errors = [err];

throughStream.emit('error', error);
throughStream.destroy(error);
});
} else {
throughStream.emit('complete', metadata);
}

throughStream.end();
});

return throughStream;
Expand Down Expand Up @@ -1669,7 +1665,7 @@ File.prototype.startResumableUpload_ = function(stream, metadata) {
return;
}

stream.emit('error', err);
stream.destroy(err);
}
};

Expand Down Expand Up @@ -1708,7 +1704,6 @@ File.prototype.startSimpleUpload_ = function(stream, metadata) {
that.metadata = data;

stream.emit('complete', data);
stream.end();
});
};

Expand Down
5 changes: 3 additions & 2 deletions test/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var request = require('request');
var retryRequest = require('retry-request');
var stream = require('stream');
var streamForward = require('stream-forward');
var through = require('through2');

var googleAuthLibraryOverride;
function fakeGoogleAuthLibrary() {
Expand Down Expand Up @@ -306,7 +307,7 @@ describe('common/util', function() {
it('should emit an error', function(done) {
var error = new Error('Error.');

var ws = new stream.Writable();
var ws = through();
ws.on('error', function(err) {
assert.equal(err, error);
done();
Expand Down Expand Up @@ -840,7 +841,7 @@ describe('common/util', function() {

var stream = this;
setImmediate(function() {
assert.strictEqual(stream._readableState.ended, true);
assert.strictEqual(stream._destroyed, true);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('Request', function() {

stream.on('error', function() {
setImmediate(function() {
assert.strictEqual(stream._readableState.ended, true);
assert.strictEqual(stream._destroyed, true);
done();
});
});
Expand Down
29 changes: 12 additions & 17 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ function FakeDuplexify() {
this.setWritable = function(setWritableStream) {
writableStream = setWritableStream;
};
this.destroy = function(err) {
if (err) {
this.emit('error', err);
} else {
this.end();
}
};
}
nodeutil.inherits(FakeDuplexify, stream.Duplex);

Expand Down Expand Up @@ -550,12 +557,6 @@ describe('File', function() {
done();
});
});

it('should destroy the through stream', function(done) {
var readStream = file.createReadStream();
readStream.once('error', util.noop);
readStream.destroy = done;
});
});
});

Expand Down Expand Up @@ -650,11 +651,6 @@ describe('File', function() {
done();
});
});

it('should destroy the through stream', function(done) {
var readStream = file.createReadStream();
readStream.destroy = done;
});
});
});

Expand Down Expand Up @@ -748,15 +744,14 @@ describe('File', function() {
'bad-data', fakeResponse.crc32c);

var readStream = file.createReadStream({ validation: 'md5' });
readStream.destroy = done;
readStream.end = done;
});

it('should destroy after successful validation', function(done) {
requestOverride = getFakeSuccessfulRequest(
data, fakeResponse.crc32c);
requestOverride = getFakeSuccessfulRequest(data, fakeResponse.crc32c);

var readStream = file.createReadStream({ validation: 'crc32c' });
readStream.destroy = done;
readStream.end = done;
});
});
});
Expand Down Expand Up @@ -822,11 +817,11 @@ describe('File', function() {
file.createReadStream({ start: startOffset, end: endOffset });
});

it('should destroy the through stream', function(done) {
it('should end the through stream', function(done) {
requestOverride = getFakeSuccessfulRequest('body', { body: null });

var readStream = file.createReadStream({ start: 100 });
readStream.destroy = done;
readStream.end = done;
});
});

Expand Down