-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.js
More file actions
25 lines (25 loc) · 717 Bytes
/
Copy pathdecoder.js
File metadata and controls
25 lines (25 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var iconv = require('iconv-lite');
var StringDecoder = require('string_decoder').StringDecoder;
function defaultDecoder(data) {
var decoder = new StringDecoder();
var out = decoder.write(data) + decoder.end();
return out.replace(/\0/g, '').trim();
}
module.exports = createDecoder;
function createDecoder(encoding) {
if (!encoding) {
return defaultDecoder;
}
if (!iconv.encodingExists(encoding)) {
if (encoding.length > 5 && iconv.encodingExists(encoding.slice(5))) {
encoding = encoding.slice(5);
} else {
return defaultDecoder;
}
}
return decoder;
function decoder(buffer) {
var out = iconv.decode(buffer, encoding);
return out.replace(/\0/g, '').trim();
}
}