本文整理匯總了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");
};