Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (ret === '1') {
toastr.success(LANG['editor']['success'](path), LANG_T['success']);
// 刷新目录(显示更改时间、大小等)
self.files.refreshPath();
} else {
toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '<br>' + ret), LANG_T['error']);
}
}).catch((err) => {
});
} else if (id.startsWith('mode_')) {
let mode = id.split('_')[1];
editor.session.setMode(`ace/mode/${mode}`);
} else if (id.startsWith('encode_')) {
let encode = id.split('_')[1];
editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString());
} else if (id === 'refresh') {
// 获取文件代码
win.progressOn()
this.core.request(
this.core.filemanager.read_file({
path: path
})
).then((res) => {
win.progressOff();
name = path.substr(path.lastIndexOf('/') + 1);
if (openfileintab == false) {
win.setText(LANG['editor']['title'](antSword.noxss(path)));
} else {
win.setText(`<i class="fa fa-file-o"></i> ${antSword.noxss(name)}`);
}
ext = name.substr(name.lastIndexOf('.') + 1);
.then(buffer => iconv.decode(buffer, cs))
// .tap(html => debug('decoded html:', string(html).summary(64)))
xmlEncoding = getEncodingFromXML(body),
contentEncoding = xmlEncoding || httpEncoding;
if (!httpEncoding && !xmlEncoding) {
log('no encoding information. setting contentEncoding to utf8... (url: %s)', url);
contentEncoding = 'utf8';
}
if ((httpEncoding && xmlEncoding) && (httpEncoding !== xmlEncoding)) {
log('encoding is different between http header and xml header. (http: %s, xml: %s, url: %s)', httpEncoding, xmlEncoding, url);
}
if (contentEncoding.substr(0, 3) !== 'utf') { // content should be decoded
log('encoding %s detected. decoding... (url: %s)', contentEncoding, url);
body = iconv.decode(bufBody, contentEncoding);
}
feedparser.end(body);
});
});
(err, stdout, stderr) => {
console.log(
err,
iconv.decode(stdout, 'cp936'),
iconv.decode(stderr, 'cp936')
)
}
)
decoder: function (str) {
var reg = /%([0-9A-F]{2})/ig;
var result = [];
var parts = reg.exec(str);
while (parts) {
result.push(parseInt(parts[1], 16));
parts = reg.exec(str);
}
return String(iconv.decode(SaferBuffer.from(result), 'shift_jis'));
}
}), { 県: '大阪府' });
module.exports = async (ctx) => {
const { area } = ctx.params;
const link = 'http://oil.usd-cny.com/';
const response = await got({
method: 'get',
url: link,
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response.data, 'gb2312'));
const $list = $('.content')
.eq(0)
.find('table tbody tr');
const resultItem = [];
let areaName = '';
const updateTime = $('.time')
.text()
.split(':')[1];
const labelList = $list
.eq(1)
.find('td')
.slice(1)
.map((index, item) => $(item).text())
.get();
for (let i = 2; i < $list.length; i++) {
}).pipe(es.through(function(data) {
//get charset from
//then convert gb2312,gbk,big5 etc to utf-8
var result = data.toString('utf-8');
var meta = result.match(/<\?(.*?)\?>/g);
if (meta !== null) {
meta = meta[0].toString().match(/encoding="(.*?)"\?>/g);
encoding = meta.toString().split('"')[1];
}
//iconv-lite , which can support windows
result = iconv.decode(data, encoding);
this.emit('data', result);
})).pipe(feedparser);
const buff = Buffer.from(thridContentText, transferEncoding)
plainText = iconv.decode(buff, charset || 'utf-8')
} else {
try {
plainText = Buffer.from(thridContentText, transferEncoding).toString()
} catch (e) {
plainText = thridContentText
}
}
result.bodyText = plainText
} else if (contentType.match(htmlTypeReg)) {
let htmlText = ''
if (transferEncoding === 'base64') {
const charset = subText.match(secondChartsetReg) && subText.match(secondChartsetReg)[1].replace(/"/g, '')
const htmlBuffer = Buffer.from(thridContentText, 'base64')
htmlText = iconv.decode(htmlBuffer, charset || 'utf-8')
} else if (transferEncoding === 'quoted-printable') {
const charset = subText.match(secondChartsetReg) && subText.match(secondChartsetReg)[1].replace(/"/g, '')
let quotedHtml
if (charset && !charset.match(/utf/i)) {
quotedHtml = iconv.decode(quotedPrintable.decode(thridContentText), charset)
} else {
quotedHtml = utf8.decode(quotedPrintable.decode(thridContentText))
}
htmlText = quotedHtml
} else {
try {
htmlText = Buffer.from(thridContentText, transferEncoding).toString()
} catch (e) {
htmlText = thridContentText
}
}
export function convertFilenameEncoding(filePath: string): string | undefined {
for (const enc of iconvLiteSupportedEncodings) {
try {
const fpath = iconv.decode(Buffer.from(filePath, 'binary'), enc)
if (fs.existsSync(fpath)) {
return fpath
}
} catch (e) {
}
}
return undefined
}
function pushString(array, addr){
if(addr==0){
array.push('未知');
return 0;
}
var buf = new Buffer(255);
var stringEnd = addr;
while(geodat[stringEnd]){
stringEnd++;
}
array.push(iconv.decode(geodat.slice(addr, stringEnd), 'GBK'));
return stringEnd;
}