Skip to content

Commit c7828cf

Browse files
author
jenweber
committed
patch in mime.charsets.lookup #105
1 parent 1d2463c commit c7828cf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/s3.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ module.exports = CoreObject.extend({
102102
}
103103
},
104104

105+
_mimeCharsetsLookup: function(mimeType, fallback) {
106+
// the node-mime library removed this method in v 2.0. This is the replacement
107+
// code for what was formerly mime.charsets.lookup
108+
return (/^text\/|^application\/(javascript|json)/).test(mimeType) ? 'UTF-8' : fallback;
109+
},
110+
105111
_putObject: function(filePath, options, filePaths) {
106112
var plugin = this.plugin;
107113
var cwd = options.cwd;
@@ -119,7 +125,7 @@ module.exports = CoreObject.extend({
119125
var basePath = path.join(cwd, filePath);
120126
var data = fs.readFileSync(basePath);
121127
var contentType = mime.getType(basePath);
122-
var encoding = mime.charsets.lookup(contentType);
128+
var encoding = this._mimeCharsetsLookup(contentType);
123129
var key = prefix === '' ? filePath : [prefix, filePath].join('/');
124130
var isGzipped = gzippedFilePaths.indexOf(filePath) !== -1;
125131
var isBrotliCompressed = brotliCompressedFilePaths.indexOf(filePath) !== -1;
@@ -128,14 +134,14 @@ module.exports = CoreObject.extend({
128134
var basePathUngzipped = path.basename(basePath, '.gz');
129135
if (filePaths && filePaths.indexOf(basePathUngzipped) !== -1) {
130136
contentType = mime.getType(basePathUngzipped);
131-
encoding = mime.charsets.lookup(contentType);
137+
encoding = this._mimeCharsetsLookup(contentType);
132138
}
133139
}
134140
if (isBrotliCompressed) {
135141
var basePathUncompressed = path.basename(basePath, '.br');
136142
if (filePaths && filePaths.indexOf(basePathUncompressed) !== -1) {
137143
contentType = mime.getType(basePathUncompressed);
138-
encoding = mime.charsets.lookup(contentType);
144+
encoding = this._mimeCharsetsLookup(contentType);
139145
}
140146
}
141147

0 commit comments

Comments
 (0)