Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(err, content)=>{
if (err) {
this.logger.error('Could not read static file ' + this.source_description.link);
this.emitter.emit('error','No input file');
} else {
try {
this.logger.profile("Charset conversion to UTF-8");
if (!this.source_description.parameters.charset || this.source_description.parameters.charset === 'auto') {
let encoding = detect_encoding(content);
this.logger.info('Detected encoding ' + encoding.encoding + ' with a confidence of ' + encoding.confidence + '%.');
this.input_data = convert_encoding(content, 'UTF-8', encoding.encoding).utf8Slice();
} else {
this.input_data = convert_encoding(content, 'UTF-8', this.source_description.parameters.charset).utf8Slice();
// OPTIONAL not using ICU encodings and just assume utf8: this.input_data = content.utf8Slice();
}
this.logger.profile("Charset conversion to UTF-8");
this.emitter.emit('provideDataFinish');
} catch(err) {
this.logger.error('Could not convert encoding for ' + this.source_description.link);
this.emitter.emit('error',err);
}
}
});
}
QPStream.prototype.flush = function(){
var buffer = mimelib.decodeQuotedPrintable(this.current, false, this.charset);
if(this.charset.toLowerCase() == "binary"){
// do nothing
}else if(this.charset.toLowerCase() != "utf-8"){
buffer = encodinglib.convert(buffer, "utf-8", this.charset);
}else{
buffer = new Buffer(buffer, "utf-8");
}
this.length += buffer.length;
this.checksum.update(buffer);
this.emit("data", buffer);
};
res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
}
// found charset
if (res) {
charset = res.pop();
// prevent decode issues when sites use incorrect encoding
// ref: https://hsivonen.fi/encoding-menu/
if (charset === 'gb2312' || charset === 'gbk') {
charset = 'gb18030';
}
}
// turn raw buffers into a single utf-8 buffer
return convert(
Buffer.concat(this._raw)
, encoding
, charset
);
};
res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
}
// found charset
if (res) {
charset = res.pop();
// prevent decode issues when sites use incorrect encoding
// ref: https://hsivonen.fi/encoding-menu/
if (charset === 'gb2312' || charset === 'gbk') {
charset = 'gb18030';
}
}
// turn raw buffers into a single utf-8 buffer
return convert(
Buffer.concat(this._raw)
, encoding
, charset
);
};
function onRecordLoad(record) {
if (record._id) {
record.Name = encoding.convert(record.Name, 'UTF-8', 'EUC-KR').toString();
console.log(record._id, record.Name);
record.Chat1 = encoding.convert(record.Chat1, 'UTF-8', 'EUC-KR').toString();
record.Chat2 = encoding.convert(record.Chat2, 'UTF-8', 'EUC-KR').toString();
record.Chat3 = encoding.convert(record.Chat3, 'UTF-8', 'EUC-KR').toString();
record.Chat4 = encoding.convert(record.Chat4, 'UTF-8', 'EUC-KR').toString();
record.Chat5 = encoding.convert(record.Chat5, 'UTF-8', 'EUC-KR').toString();
db.NPC.create(record, function(err, doc) {
if (err) {
console.error(err);
return;
}
console.log('Confirming save of '+doc._id);
});
}
}
);
decodeBase64: function(str, toCharset, fromCharset) {
var buffer = new Buffer((str || "").toString(), "base64");
return convert(buffer, toCharset, fromCharset);
},
encodeBase64: function(str, toCharset, fromCharset){
var buffer = convert(str || "", toCharset, fromCharset);
return addSoftLinebreaks(buffer.toString("base64"), "base64");
},
request(url, requestOptions, function(err, res, buffer) {
if (err) {
return callback(err);
}
var contentType = parseContentType(res.headers['content-type']);
if (contentType.mimeType === 'text/html') {
contentType.charset = findHTMLCharset(buffer) || contentType.charset;
}
contentType.charset = (options.overrideEncoding || contentType.charset || 'utf-8').trim().toLowerCase();
if (!contentType.charset.match(/^utf-?8$/i)) {
buffer = encodinglib.convert(buffer, 'UTF-8', contentType.charset);
}
buffer = buffer.toString();
if (options.preprocess) {
options.preprocess(buffer, res, contentType, function(preprocessErr, data) {
if (preprocessErr) {
return callback(preprocessErr);
}
callback(null, res, data);
});
} else {
callback(null, res, buffer);
}
});
}
decodeMimeWord: function(str, toCharset){
str = (str || "").toString().trim();
var fromCharset, encoding, match;
match = str.match(/^\=\?([\w_\-]+)\?([QB])\?([^\?]+)\?\=$/i);
if(!match){
return convert(str, toCharset);
}
fromCharset = match[1];
encoding = (match[2] || "Q").toString().toUpperCase();
str = (match[3] || "").replace(/_/g, " ");
if(encoding == "B"){
return this.decodeBase64(str, toCharset, fromCharset);
}else if(encoding == "Q"){
return this.mimeDecode(str, toCharset, fromCharset);
}else{
return str;
}
},
}), i.on("end", function ()
{
var e = Buffer.concat(a, s), t = e.toString();
if ("pol" == n && t.indexOf("�") >= 0)
{
var o = encoding.convert(e, "utf8", "cp1250").toString();
o.indexOf("�") < 0 && (t = o)
}
resolve(t)
}), i.on("error", reject)
}, i, [s[0].IDSubtitleFile]) : reject({token: i, moviehash: t, subfilename: e})