本文整理汇总了TypeScript中iconv-lite.decodeStream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript decodeStream函数的具体用法?TypeScript decodeStream怎么用?TypeScript decodeStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decodeStream函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
(() => {
// Decode stream (from binary stream to js strings)
http.createServer(function(req, res) {
var converterStream = iconv.decodeStream('win1251');
req.pipe(converterStream);
converterStream.on('data', function(str: string) {
console.log(str); // Do something with decoded strings, chunk-by-chunk.
});
});
// Convert encoding streaming example
fs.createReadStream('file-in-win1251.txt')
.pipe(iconv.decodeStream('win1251'))
.pipe(iconv.encodeStream('ucs2'))
.pipe(fs.createWriteStream('file-in-ucs2.txt'));
// Sugar: all encode/decode streams have .collect(cb) method to accumulate data.
http.createServer(function(req, res) {
req.pipe(iconv.decodeStream('win1251')).collect(function(err, body) {
assert(typeof body == 'string');
console.log(body); // full request body string
});
});
})();
示例2: reject
storage.createBlobService().getBlobToStream(process.env.AZURE_BLOB_STORAGE, targetBlob, fs.createWriteStream(localFile), err => {
if (err) {
return reject(err);
}
let stream = fs.createWriteStream(localFile, {flags:'a'});
const readableStream = fs.createReadStream(localFile)
.pipe(iconv.decodeStream('SJIS'))
.pipe(iconv.encodeStream('UTF-8'))
.pipe(csv.parse());
readableStream.on('data', (record) => {
docs.push(record);
});
readableStream.on('end', () => {
if (configs.csv.csv_101.useHeader) docs.shift();
fs.unlink(localFile, () => {});
return resolve(docs);
});
});
示例3: resolveTerminalEncoding
resolveTerminalEncoding(verbose).then(encoding => {
const converterStream = iconv.decodeStream(encoding);
process.stdin.pipe(converterStream).pipe(stdinFileStream);
});
示例4:
http.createServer(function(req, res) {
req.pipe(iconv.decodeStream('win1251')).collect(function(err, body) {
assert(typeof body == 'string');
console.log(body); // full request body string
});
});