Skip to content

Commit dc4bf20

Browse files
committed
Merge pull request #322 from stephenplusplus/spp--mime-lib-switch
switch to mime-types. fixes #320
2 parents afdb3bb + 3484e3b commit dc4bf20

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

lib/storage/bucket.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var extend = require('extend');
2424
var fs = require('fs');
25-
var mime = require('mime');
25+
var mime = require('mime-types');
2626
var path = require('path');
2727

2828
/**
@@ -410,16 +410,12 @@ Bucket.prototype.upload = function(localPath, options, callback) {
410410
}
411411

412412
var metadata = options.metadata || {};
413-
var contentType = mime.lookup(localPath);
413+
var contentType = mime.contentType(path.basename(localPath));
414+
414415
if (contentType && !metadata.contentType) {
415416
metadata.contentType = contentType;
416417
}
417418

418-
var charset = mime.charsets.lookup(metadata.contentType);
419-
if (charset) {
420-
metadata.contentType += '; charset=' + charset;
421-
}
422-
423419
var resumable;
424420
if (util.is(options.resumable, 'boolean')) {
425421
resumable = options.resumable;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"extend": "^1.3.0",
5151
"fast-crc32c": "^0.1.3",
5252
"google-service-account": "^1.0.3",
53-
"mime": "^1.2.11",
53+
"mime-types": "^2.0.3",
5454
"node-uuid": "^1.4.1",
5555
"protobufjs": "^3.4.0",
5656
"request": "^2.39.0",

test/storage/bucket.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ describe('Bucket', function() {
353353
fakeFile.createWriteStream = function(options) {
354354
var dup = duplexify();
355355
setImmediate(function() {
356-
assert.equal(options.metadata.contentType, 'application/json');
356+
var expectedContentType = 'application/json; charset=utf-8';
357+
assert.equal(options.metadata.contentType, expectedContentType);
357358
done();
358359
});
359360
return dup;
@@ -367,8 +368,8 @@ describe('Bucket', function() {
367368
fakeFile.createWriteStream = function(options) {
368369
var dup = duplexify();
369370
setImmediate(function() {
370-
assert.equal(
371-
options.metadata.contentType, 'text/plain; charset=UTF-8');
371+
var expectedContentType = 'text/plain; charset=utf-8';
372+
assert.equal(options.metadata.contentType, expectedContentType);
372373
done();
373374
});
374375
return dup;

0 commit comments

Comments
 (0)