本文整理汇总了TypeScript中iconv-lite.encode函数的典型用法代码示例。如果您正苦于以下问题:TypeScript encode函数的具体用法?TypeScript encode怎么用?TypeScript encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("Big5", () => {
const testData = "能 脊 胼 胯 臭 臬 舀 舐 航 舫 舨 般 芻 茫 荒 荔";
const textEncoding = "Big5";
writeFileSync(editor.tempFile, encode(testData, textEncoding), {encoding: "binary"});
const result = editor.run();
assert.equal(testData, result);
});
示例2: it
it('detects and decodes utf-16be bom document', () => {
var doc = linez(Buffer.concat([
new Buffer([0xfe, 0xff]),
iconv.encode('foo', 'utf16be')
]));
expect(doc.charset).to.eq('utf-16be');
expect(doc.lines[0].text).to.eq('foo');
});
示例3: getMacHexCode
function getMacHexCode(str: string, i: number, macCodePages: any) {
const code = str.charCodeAt(i)
if (code < 128) {
return code.toString(16)
}
else if (code < 256) {
return iconv.encode(str[i], "macroman").toString("hex")
}
else {
for (let i = 0; i < macCodePages.length; i++) {
const result = iconv.encode(str[i], macCodePages[i]).toString("hex")
if (result !== undefined) {
return result
}
}
}
return code
}
示例4: 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");
})();
示例5: encodeContent
export async function encodeContent (content: Buffer, encoding: string, charset: Charset) {
content = charsetEncoder.encode(content, charset.get(), { addBOM: charset.isFromBOM() });
if (encoding === GZIP_CONTENT_ENCODING)
return gzip(content);
if (encoding === DEFLATE_CONTENT_ENCODING)
return deflate(content);
if (encoding === BROTLI_CONTENT_ENCODING)
return Buffer.from(require('brotli').compress(content));
return content;
}
示例6: async
router.get('/export/:format', async (req, res) => {
const storage = botScopedStorage.get(req.params.botId)
const config = await bp.config.getModuleConfigForBot('qna', req.params.botId)
const data = await prepareExport(storage, { flat: true })
if (req.params.format === 'csv') {
res.setHeader('Content-Type', 'text/csv')
res.setHeader('Content-disposition', `attachment; filename=qna_${moment().format('DD-MM-YYYY')}.csv`)
const categoryWrapper = storage.hasCategories() ? ['category'] : []
const parseOptions = {
fields: ['question', 'action', 'answer', 'answer2', ...categoryWrapper],
header: true
}
const json2csvParser = new Json2csvParser(parseOptions)
res.end(iconv.encode(json2csvParser.parse(data), config.exportCsvEncoding))
} else {
res.setHeader('Content-Type', 'application/json')
res.setHeader('Content-disposition', `attachment; filename=qna_${moment().format('DD-MM-YYYY')}.json`)
res.end(JSON.stringify(data))
}
})
示例7:
encode: (str, enc) => {
encodings.add(enc);
return iconvLite.encode(str, enc)
},
示例8: generateUserNameBuf
/***
* Generate a userName Buffer. Currently hardcoded to CP-850, but the
* true char encoding is LMBCS
* @param {string} userName The username to be converted to a CP-850 buffer
* @returns {buffer} Username encoded in CP-850 and stuffed into a Buffer
*/
function generateUserNameBuf(userName: string): Buffer {
return encode(userName, "ibm850");
};