diff --git a/lib/storage/file.js b/lib/storage/file.js index 58390e6cab9..1c90b40c82e 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -442,6 +442,9 @@ File.prototype.createReadStream = function(options) { } if (rangeRequest) { + if (is.string(options.validation) || options.validation === true) { + throw new Error('Cannot use validation with file ranges (start/end).'); + } // Range requests can't receive data integrity checks. crc32c = false; md5 = false; diff --git a/test/storage/file.js b/test/storage/file.js index 582ae978502..ccd3ea31569 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -86,7 +86,6 @@ describe('File', function() { mockery.registerMock('sse4_crc32', crc32c); mockery.registerMock('configstore', FakeConfigStore); - // mockery.registerMock('duplexify', FakeDuplexify); mockery.registerMock('request', fakeRequest); mockery.registerMock('../common/util.js', fakeUtil); mockery.enable({ @@ -451,6 +450,37 @@ describe('File', function() { return FakeFailedRequest; } + it('should throw if both a range and validation is given', function() { + assert.throws(function() { + file.createReadStream({ + validation: true, + start: 3, + end: 8 + }); + }, /Cannot use validation with file ranges/); + + assert.throws(function() { + file.createReadStream({ + validation: true, + start: 3 + }); + }, /Cannot use validation with file ranges/); + + assert.throws(function() { + file.createReadStream({ + validation: true, + end: 8 + }); + }, /Cannot use validation with file ranges/); + + assert.doesNotThrow(function() { + file.createReadStream({ + start: 3, + end: 8 + }); + }); + }); + it('should send query.generation if File has one', function(done) { var versionedFile = new File(bucket, 'file.txt', { generation: 1 });