You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
510 B
JavaScript
20 lines
510 B
JavaScript
'use strict';
|
|
|
|
const iconvLite = require("iconv-lite");
|
|
|
|
let encodingMap = {
|
|
"ascii": "ascii",
|
|
/* The following are strictly not the same thing, but there's backwards compatibility. */
|
|
"ucs2-level1": "utf16-be",
|
|
"ucs2-level2": "utf16-be",
|
|
"ucs2-level3": "utf16-be"
|
|
}
|
|
|
|
module.exports = function decode(buffer, encoding) {
|
|
if (encodingMap[encoding] == null) {
|
|
throw new Error(`No such encoding: ${encoding}`);
|
|
}
|
|
|
|
return iconvLite.decode(buffer, encodingMap[encoding]);
|
|
};
|