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