Skip to content

Commit 64670b5

Browse files
committed
use safe-buffer. Fixes #585
1 parent 1a9662d commit 64670b5

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

lib/parsers/string.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1+
var Buffer = require('safe-buffer').Buffer;
12
var Iconv = require('iconv-lite');
23

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-
}, {});
16-
174
exports.decode = function(buffer, encoding, options) {
18-
if (NODE_ENCODING[encoding]) {
5+
if (Buffer.isEncoding(encoding)) {
196
return buffer.toString(encoding);
207
}
218

@@ -28,7 +15,7 @@ exports.decode = function(buffer, encoding, options) {
2815
};
2916

3017
exports.encode = function(string, encoding, options) {
31-
if (NODE_ENCODING[encoding]) {
18+
if (Buffer.isEncoding(encoding)) {
3219
return Buffer.from(string, encoding);
3320
}
3421

0 commit comments

Comments
 (0)