本文整理汇总了TypeScript中iconv-lite.decode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript decode函数的具体用法?TypeScript decode怎么用?TypeScript decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
router.post('/import/csv', upload.single('csv'), async (req, res) => {
const storage = botScopedStorage.get(req.params.botId)
const config = await bp.config.getModuleConfigForBot('qna', req.params.botId)
const uploadStatusId = nanoid()
res.end(uploadStatusId)
updateUploadStatus(uploadStatusId, 'Deleting existing questions')
if (yn(req.body.isReplace)) {
const questions = await storage.fetchAllQuestions()
const statusCb = processedCount =>
updateUploadStatus(uploadStatusId, `Deleted ${processedCount}/${questions.length} questions`)
await storage.delete(questions.map(({ id }) => id), statusCb)
}
try {
const questions = iconv.decode(req.file.buffer, config.exportCsvEncoding)
const params = {
storage,
config,
format: 'csv',
statusCallback: updateUploadStatus,
uploadStatusId
}
await importQuestions(questions, params)
updateUploadStatus(uploadStatusId, 'Completed')
} catch (e) {
bp.logger.error('Upload error :', e)
updateUploadStatus(uploadStatusId, `Error: ${e.message}`)
}
})
示例2: getNewsContent
public async getNewsContent(newsURL: string): Promise<NewsContent> {
try {
await delay(5000);
const response = await request({
uri: newsURL,
headers: commonHeaders,
encoding: null,
});
let $ = cheerio.load(response);
$('script').remove();
const encodedResponse = iconv.decode(response, $('meta[charset]').attr('charset')).toString();
$ = cheerio.load(encodedResponse);
const newsTitle = $('meta[property=\'og:title\']').attr('content');
const newsContent = $('#articeBody, #newsEndContents, #articleBodyContents');
return {
title: newsTitle,
content: newsContent.html(),
plain_text: newsContent.text(),
press: $('.press_logo img, #pressLogo img').attr('alt'),
link: newsURL,
};
} catch (err) {
logger.error(err);
}
}
示例3:
}).then(function(result): Buffer {
if (encoding != null && encoding != "") {
var decoded = iconv.decode(result.stdout, encoding);
return decoded;
}
return result.stdout;
}).fail(function(error) {
示例4: Error
testFixture.forEach(set => {
console.log('File:', set.file);
console.log('Exists:', fs.existsSync(set.file));
if (fs.existsSync(set.file)) {
let data = fs.readFileSync(set.file);
data = iconv.decode(data, "ISO-8859-1");
let parse = new ParseCSV(data);
let nice = parse.parseAndNormalize();
if (nice.length != set.rows) {
console.log('parsed', nice.length, 'rows, expecting', set.rows);
console.log(nice);
throw new Error('number of rows is not the same');
}
let row0 = this.pluckImportant(nice[0]);
let row1 = this.pluckImportant(nice[1]);
// if (_.isEqual(row0, set.result[0]) && _.isEqual(row1, set.result[1])) {
if (JSON.stringify(row0) == JSON.stringify(set.result[0])
&& JSON.stringify(row1) == JSON.stringify(set.result[1])) {
console.log('OK');
} else {
console.error('Parsed file does not match');
console.log(JSON.stringify(row0, null, 4));
console.log(JSON.stringify(set.result[0], null, 4));
console.log(JSON.stringify(row1, null, 4));
console.log(JSON.stringify(set.result[1], null, 4));
throw new Error(set.file + ' test failed');
}
}
});
示例5: sendPromise
async function sendPromise(){
let data = await send("http://bcy.net/coser/");
let ddd = await zibPromise(data);
data = iconv.decode(ddd, 'utf-8');
console.log(data);
}
示例6: Buffer
(() => {
// Convert from an encoded buffer to js string.
const str: string = iconv.decode(new Buffer([0x68, 0x65, 0x6c, 0x6c, 0x6f]), 'win1251');
// Convert from js string to an encoded buffer.
const buf: Buffer = iconv.encode("Sample input string", 'win1251');
// Check if encoding is supported
const exists: boolean = iconv.encodingExists("us-ascii");
})();
示例7: resolve
return new Promise<vscode.Hover>((resolve) => {
const charEncoding = vscode.workspace.getConfiguration('hexdump').get<string>('charEncoding');
const littleEndian = vscode.workspace.getConfiguration('hexdump').get<boolean>('littleEndian');
const showInspector = vscode.workspace.getConfiguration('hexdump').get<boolean>('showInspector');
if (!showInspector) {
return resolve();
}
let offset = getOffset(position);
if (typeof offset == 'undefined') {
return resolve();
}
var content: string = 'Hex Inspector';
content += littleEndian ? ' Little Endian\n' : ' Big Endian\n';
content += 'Address: 0x' + sprintf('%08X', offset) + '\n';
let sel = vscode.window.activeTextEditor.selection;
if (sel.contains(position)) {
let start = getOffset(sel.start);
let end = getOffset(sel.end);
content += 'Selection: 0x' + sprintf('%08X', start)
content += ' - 0x' + sprintf('%08X', end) + ' \n';
}
let buf = getBuffer(document.uri);
if (typeof buf == 'undefined') {
return resolve();
}
let arrbuf = toArrayBuffer(buf, offset, 8);
var view = new DataView(arrbuf);
content += 'Int8: ' + sprintf('%12d', view.getInt8(0)) + '\t';
content += 'Uint8: ' + sprintf('%12d', view.getUint8(0)) + ' \n';
content += 'Int16: ' + sprintf('%12d', view.getInt16(0, littleEndian)) + '\t';
content += 'Uint16: ' + sprintf('%12d', view.getUint16(0, littleEndian)) + ' \n';
content += 'Int32: ' + sprintf('%12d', view.getInt32(0, littleEndian)) + '\t';
content += 'Uint32: ' + sprintf('%12d', view.getUint32(0, littleEndian)) + ' \n';
content += 'Int64: ' + Long.fromBytes(new Uint8Array(arrbuf), true, littleEndian).toString() + ' \n';
content += 'Uint64: ' + Long.fromBytes(new Uint8Array(arrbuf), false, littleEndian).toString() + ' \n';
content += 'Float32: ' + sprintf('%f', view.getFloat32(0, littleEndian)) + ' \n';
content += 'Float64: ' + sprintf('%f', view.getFloat64(0, littleEndian)) + ' \n';
content += '\n';
if (sel.contains(position)) {
let start = getOffset(sel.start);
let end = getOffset(sel.end) + 1;
content += 'String (' + charEncoding + '):\n';
let conv = iconvLite.decode(buf.slice(start, end), charEncoding);
content += conv.toString();
}
return resolve(new vscode.Hover( {language: 'hexdump', value: content} )) ;
});
示例8: _handleDataChunk
private _handleDataChunk(data: Buffer) {
// Anatomy of packets: [data length] [NULL] [xml] [NULL]
// are we waiting for the data length or for the response?
if (this._parsingState === ParsingState.DataLength) {
// does data contain a NULL byte?
const nullByteIndex = data.indexOf(0);
if (nullByteIndex !== -1) {
// YES -> we received the data length and are ready to receive the response
this._dataLength = parseInt(iconv.decode(data.slice(0, nullByteIndex), ENCODING));
// reset buffered chunks
this._chunks = [];
this._chunksDataLength = 0;
// switch to response parsing state
this._parsingState = ParsingState.Response;
// if data contains more info (except the NULL byte)
if (data.length > nullByteIndex + 1) {
// handle the rest of the packet as part of the response
const rest = data.slice(nullByteIndex + 1);
this._handleDataChunk(rest);
}
} else {
// NO -> this is only part of the data length. We wait for the next data event
this._chunks.push(data);
this._chunksDataLength += data.length;
}
} else if (this._parsingState === ParsingState.Response) {
// does the new data together with the buffered data add up to the data length?
if (this._chunksDataLength + data.length >= this._dataLength) {
// YES -> we received the whole response
// append the last piece of the response
const lastResponsePiece = data.slice(0, this._dataLength - this._chunksDataLength);
this._chunks.push(lastResponsePiece);
this._chunksDataLength += data.length;
const response = Buffer.concat(this._chunks, this._chunksDataLength);
// call response handler
this.handleResponse(parseResponse(response));
// reset buffer
this._chunks = [];
this._chunksDataLength = 0;
// switch to data length parsing state
this._parsingState = ParsingState.DataLength;
// if data contains more info (except the NULL byte)
if (data.length > lastResponsePiece.length + 1) {
// handle the rest of the packet (after the NULL byte) as data length
const rest = data.slice(lastResponsePiece.length + 1);
this._handleDataChunk(rest);
}
} else {
// NO -> this is not the whole response yet. We buffer it and wait for the next data event.
this._chunks.push(data);
this._chunksDataLength += data.length;
}
}
}
示例9: decode
decode(
data: DataView,
byteOffset: number,
byteLength: number,
encoding: string,
): string {
const buffer = Buffer.from(
data.buffer,
data.byteOffset + byteOffset,
byteLength,
)
return decode(buffer, encoding)
}
示例10: Buffer
rollbar.invoke('Processing "data" event from proc stdout', {data, command, args}, () => {
const str = iconv.decode(new Buffer(data), encoding);
const lines = str.split('\n').map(l => l.endsWith('\r') ? l.substr(0, l.length - 1) : l);
while (lines.length > 1) {
line_acc += lines[0];
if (outputConsumer) {
outputConsumer.output(line_acc);
}
line_acc = '';
// Erase the first line from the list
lines.splice(0, 1);
}
console.assert(lines.length, 'Invalid lines', JSON.stringify(lines));
line_acc += lines[0];
stdout_acc += str;
});