Skip to content

Commit 93d7a12

Browse files
storage: use standard URL instead of calling getMetadata - fixes #524
1 parent 686fe62 commit 93d7a12

File tree

2 files changed

+12
-51
lines changed

2 files changed

+12
-51
lines changed

lib/storage/file.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,12 @@ File.prototype.createReadStream = function(options) {
321321
var crc32c = validation === 'crc32c' || validation === 'all';
322322
var md5 = validation === 'md5' || validation === 'all';
323323

324-
if (this.metadata.mediaLink) {
325-
createAuthorizedReq(this.metadata.mediaLink);
326-
} else {
327-
this.getMetadata(function(err, metadata, resp) {
328-
if (err) {
329-
done(err, resp);
330-
return;
331-
}
324+
var remoteFilePath = util.format('https://{b}.storage.googleapis.com/{o}', {
325+
b: this.bucket.name,
326+
o: encodeURIComponent(this.name)
327+
});
332328

333-
createAuthorizedReq(metadata.mediaLink);
334-
});
335-
}
329+
createAuthorizedReq(remoteFilePath);
336330

337331
return throughStream;
338332

test/storage/file.js

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -274,50 +274,25 @@ describe('File', function() {
274274
});
275275

276276
describe('createReadStream', function() {
277-
var metadata = { mediaLink: 'filelink' };
278-
279-
it('should confirm file exists before reading', function(done) {
280-
file.getMetadata = function() {
281-
done();
282-
};
283-
file.createReadStream();
284-
});
285-
286-
it('should emit error if stat returns error', function(done) {
287-
var error = new Error('Error.');
288-
file.getMetadata = function(callback) {
289-
setImmediate(function() {
290-
callback(error);
291-
});
292-
};
293-
file.createReadStream()
294-
.once('error', function(err) {
295-
assert.equal(err, error);
296-
done();
297-
});
298-
});
299-
300277
it('should create an authorized request', function(done) {
278+
var expectedPath = util.format('https://{b}.storage.googleapis.com/{o}', {
279+
b: file.bucket.name,
280+
o: encodeURIComponent(file.name)
281+
});
282+
301283
file.bucket.storage.makeAuthorizedRequest_ = function(opts) {
302-
assert.equal(opts.uri, metadata.mediaLink);
284+
assert.equal(opts.uri, expectedPath);
303285
done();
304286
};
305287

306-
file.getMetadata = function(callback) {
307-
callback(null, metadata);
308-
};
309-
310288
file.createReadStream();
311289
});
312290

313291
it('should emit an error from authorizing', function(done) {
314292
var error = new Error('Error.');
315293
file.bucket.storage.makeAuthorizedRequest_ = function(opts, callback) {
316-
(callback.onAuthorized || callback)(error);
317-
};
318-
file.getMetadata = function(callback) {
319294
setImmediate(function() {
320-
callback(null, metadata);
295+
(callback.onAuthorized || callback)(error);
321296
});
322297
};
323298
file.createReadStream()
@@ -346,10 +321,6 @@ describe('File', function() {
346321
};
347322
nodeutil.inherits(request_Override, stream.Readable);
348323

349-
file.getMetadata = function(callback) {
350-
callback(null, metadata);
351-
};
352-
353324
file.bucket.storage.makeAuthorizedRequest_ = function(opts, callback) {
354325
(callback.onAuthorized || callback)(null, fakeRequest);
355326
};
@@ -480,7 +451,6 @@ describe('File', function() {
480451
return duplexify();
481452
};
482453

483-
file.metadata = metadata;
484454
file.createReadStream({ start: startOffset });
485455
});
486456

@@ -495,7 +465,6 @@ describe('File', function() {
495465
return duplexify();
496466
};
497467

498-
file.metadata = metadata;
499468
file.createReadStream({ end: endOffset });
500469
});
501470

@@ -512,7 +481,6 @@ describe('File', function() {
512481
return duplexify();
513482
};
514483

515-
file.metadata = metadata;
516484
file.createReadStream({ start: startOffset, end: endOffset });
517485
});
518486

@@ -529,7 +497,6 @@ describe('File', function() {
529497
return duplexify();
530498
};
531499

532-
file.metadata = metadata;
533500
file.createReadStream({ start: startOffset, end: endOffset });
534501
});
535502
});

0 commit comments

Comments
 (0)