Skip to content

Commit 332cdf1

Browse files
authored
Check actual node-supported encodings on startup
1 parent e363378 commit 332cdf1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/parsers/string.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
var Iconv = require('iconv-lite');
22

3-
var NODE_ENCODING = {
4-
'ascii': true,
5-
'utf8': true,
6-
'utf16le': true,
7-
'ucs2': true,
8-
'base64': true,
9-
'latin1': true,
10-
'binary': true,
11-
'hex': true
12-
};
3+
var NODE_ENCODING = [
4+
'ascii',
5+
'utf8',
6+
'utf16le',
7+
'ucs2',
8+
'base64',
9+
'latin1',
10+
'binary',
11+
'hex'
12+
].reduce(function (map, item) {
13+
map[item] = Buffer.isEncoding(item);
14+
return map;
15+
}, {});
1316

1417
exports.decode = function(buffer, encoding, options) {
1518
if (NODE_ENCODING[encoding]) {

0 commit comments

Comments
 (0)