From 93d7a12812e35bf3f998fffdc535200a3ec2f656 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Mon, 4 May 2015 11:03:37 -0400 Subject: [PATCH] storage: use standard URL instead of calling getMetadata - fixes #524 --- lib/storage/file.js | 16 +++++---------- test/storage/file.js | 47 +++++++------------------------------------- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/lib/storage/file.js b/lib/storage/file.js index 823015da3ea..6cf93ff0f8d 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -321,18 +321,12 @@ File.prototype.createReadStream = function(options) { var crc32c = validation === 'crc32c' || validation === 'all'; var md5 = validation === 'md5' || validation === 'all'; - if (this.metadata.mediaLink) { - createAuthorizedReq(this.metadata.mediaLink); - } else { - this.getMetadata(function(err, metadata, resp) { - if (err) { - done(err, resp); - return; - } + var remoteFilePath = util.format('https://{b}.storage.googleapis.com/{o}', { + b: this.bucket.name, + o: encodeURIComponent(this.name) + }); - createAuthorizedReq(metadata.mediaLink); - }); - } + createAuthorizedReq(remoteFilePath); return throughStream; diff --git a/test/storage/file.js b/test/storage/file.js index f313dc1c7a6..ed137f1e0fa 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -274,50 +274,25 @@ describe('File', function() { }); describe('createReadStream', function() { - var metadata = { mediaLink: 'filelink' }; - - it('should confirm file exists before reading', function(done) { - file.getMetadata = function() { - done(); - }; - file.createReadStream(); - }); - - it('should emit error if stat returns error', function(done) { - var error = new Error('Error.'); - file.getMetadata = function(callback) { - setImmediate(function() { - callback(error); - }); - }; - file.createReadStream() - .once('error', function(err) { - assert.equal(err, error); - done(); - }); - }); - it('should create an authorized request', function(done) { + var expectedPath = util.format('https://{b}.storage.googleapis.com/{o}', { + b: file.bucket.name, + o: encodeURIComponent(file.name) + }); + file.bucket.storage.makeAuthorizedRequest_ = function(opts) { - assert.equal(opts.uri, metadata.mediaLink); + assert.equal(opts.uri, expectedPath); done(); }; - file.getMetadata = function(callback) { - callback(null, metadata); - }; - file.createReadStream(); }); it('should emit an error from authorizing', function(done) { var error = new Error('Error.'); file.bucket.storage.makeAuthorizedRequest_ = function(opts, callback) { - (callback.onAuthorized || callback)(error); - }; - file.getMetadata = function(callback) { setImmediate(function() { - callback(null, metadata); + (callback.onAuthorized || callback)(error); }); }; file.createReadStream() @@ -346,10 +321,6 @@ describe('File', function() { }; nodeutil.inherits(request_Override, stream.Readable); - file.getMetadata = function(callback) { - callback(null, metadata); - }; - file.bucket.storage.makeAuthorizedRequest_ = function(opts, callback) { (callback.onAuthorized || callback)(null, fakeRequest); }; @@ -480,7 +451,6 @@ describe('File', function() { return duplexify(); }; - file.metadata = metadata; file.createReadStream({ start: startOffset }); }); @@ -495,7 +465,6 @@ describe('File', function() { return duplexify(); }; - file.metadata = metadata; file.createReadStream({ end: endOffset }); }); @@ -512,7 +481,6 @@ describe('File', function() { return duplexify(); }; - file.metadata = metadata; file.createReadStream({ start: startOffset, end: endOffset }); }); @@ -529,7 +497,6 @@ describe('File', function() { return duplexify(); }; - file.metadata = metadata; file.createReadStream({ start: startOffset, end: endOffset }); }); });