Skip to content

Commit

Permalink
Merge pull request #322 from stephenplusplus/spp--mime-lib-switch
Browse files Browse the repository at this point in the history
switch to mime-types. fixes #320
  • Loading branch information
ryanseys committed Dec 8, 2014
2 parents afdb3bb + 3484e3b commit dc4bf20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
10 changes: 3 additions & 7 deletions lib/storage/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var extend = require('extend');
var fs = require('fs');
var mime = require('mime');
var mime = require('mime-types');
var path = require('path');

/**
Expand Down Expand Up @@ -410,16 +410,12 @@ Bucket.prototype.upload = function(localPath, options, callback) {
}

var metadata = options.metadata || {};
var contentType = mime.lookup(localPath);
var contentType = mime.contentType(path.basename(localPath));

if (contentType && !metadata.contentType) {
metadata.contentType = contentType;
}

var charset = mime.charsets.lookup(metadata.contentType);
if (charset) {
metadata.contentType += '; charset=' + charset;
}

var resumable;
if (util.is(options.resumable, 'boolean')) {
resumable = options.resumable;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"extend": "^1.3.0",
"fast-crc32c": "^0.1.3",
"google-service-account": "^1.0.3",
"mime": "^1.2.11",
"mime-types": "^2.0.3",
"node-uuid": "^1.4.1",
"protobufjs": "^3.4.0",
"request": "^2.39.0",
Expand Down
7 changes: 4 additions & 3 deletions test/storage/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ describe('Bucket', function() {
fakeFile.createWriteStream = function(options) {
var dup = duplexify();
setImmediate(function() {
assert.equal(options.metadata.contentType, 'application/json');
var expectedContentType = 'application/json; charset=utf-8';
assert.equal(options.metadata.contentType, expectedContentType);
done();
});
return dup;
Expand All @@ -367,8 +368,8 @@ describe('Bucket', function() {
fakeFile.createWriteStream = function(options) {
var dup = duplexify();
setImmediate(function() {
assert.equal(
options.metadata.contentType, 'text/plain; charset=UTF-8');
var expectedContentType = 'text/plain; charset=utf-8';
assert.equal(options.metadata.contentType, expectedContentType);
done();
});
return dup;
Expand Down

0 comments on commit dc4bf20

Please sign in to comment.