diff --git a/lib/storage/file.js b/lib/storage/file.js index c073fe23868..8a0086a5636 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -235,9 +235,10 @@ File.prototype.copy = function(destination, callback) { * with less reliability. You may also choose to skip validation completely, * however this is **not recommended**. * @param {number} options.start - A byte offset to begin the file's download - * from. NOTE: Byte ranges are inclusive; that is, `options.start = 0` and - * `options.end = 999` represent the first 1000 bytes in a file or object. - * NOTE: when specifying a byte range, data integrity is not available. + * from. Default is 0. NOTE: Byte ranges are inclusive; that is, + * `options.start = 0` and `options.end = 999` represent the first 1000 + * bytes in a file or object. NOTE: when specifying a byte range, data + * integrity is not available. * @param {number} options.end - A byte offset to stop reading the file at. * NOTE: Byte ranges are inclusive; that is, `options.start = 0` and * `options.end = 999` represent the first 1000 bytes in a file or object. @@ -325,8 +326,10 @@ File.prototype.createReadStream = function(options) { }; if (rangeRequest) { + var start = util.is(options.start, 'number') ? options.start : '0'; + var end = util.is(options.end, 'number') ? options.end : ''; reqOpts.headers = { - Range: 'bytes=' + [options.start || '', options.end || ''].join('-') + Range: 'bytes=' + start + '-' + end }; } diff --git a/test/storage/file.js b/test/storage/file.js index ba29f478807..c181248e8db 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -454,12 +454,12 @@ describe('File', function() { file.createReadStream({ start: startOffset }); }); - it('should accept an end range', function(done) { + it('should accept an end range and set start to 0', function(done) { var endOffset = 100; request_Override = function(opts) { setImmediate(function () { - assert.equal(opts.headers.Range, 'bytes=-' + endOffset); + assert.equal(opts.headers.Range, 'bytes=0-' + endOffset); done(); }); return duplexify(); @@ -485,6 +485,23 @@ describe('File', function() { file.metadata = metadata; file.createReadStream({ start: startOffset, end: endOffset }); }); + + it('should accept range start and end as 0', function(done) { + var startOffset = 0; + var endOffset = 0; + + request_Override = function(opts) { + setImmediate(function () { + var expectedRange = 'bytes=0-0'; + assert.equal(opts.headers.Range, expectedRange); + done(); + }); + return duplexify(); + }; + + file.metadata = metadata; + file.createReadStream({ start: startOffset, end: endOffset }); + }); }); describe('createWriteStream', function() {