Skip to content

Commit

Permalink
storage: use standard URL instead of calling getMetadata - fixes goog…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed May 4, 2015
1 parent 686fe62 commit f79550b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 52 deletions.
16 changes: 5 additions & 11 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
49 changes: 8 additions & 41 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
it.only('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()
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -480,7 +451,6 @@ describe('File', function() {
return duplexify();
};

file.metadata = metadata;
file.createReadStream({ start: startOffset });
});

Expand All @@ -495,7 +465,6 @@ describe('File', function() {
return duplexify();
};

file.metadata = metadata;
file.createReadStream({ end: endOffset });
});

Expand All @@ -512,7 +481,6 @@ describe('File', function() {
return duplexify();
};

file.metadata = metadata;
file.createReadStream({ start: startOffset, end: endOffset });
});

Expand All @@ -529,7 +497,6 @@ describe('File', function() {
return duplexify();
};

file.metadata = metadata;
file.createReadStream({ start: startOffset, end: endOffset });
});
});
Expand Down

0 comments on commit f79550b

Please sign in to comment.