本文整理汇总了TypeScript中streaming.readToEnd函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readToEnd函数的具体用法?TypeScript readToEnd怎么用?TypeScript readToEnd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readToEnd函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getOAuthFromFile
/**
Read accounts from tab/comma-separated values in `filepath`, which
should have the headers: consumer_key, consumer_secret, token, token_secret,
choose one at random, and use that.
*/
function getOAuthFromFile(filepath: string, callback: (error: Error, oauth?: OAuth) => void): void {
let parser = createReadStream(filepath, {encoding: 'utf8'}).pipe(new Parser());
readToEnd(parser, (error: Error, accounts: Account[]) => {
if (error) return callback(error);
let {consumer_key, consumer_secret, token, token_secret} = accounts[Math.random() * accounts.length | 0];
callback(null, {consumer_key, consumer_secret, token, token_secret});
});
}
示例2: it
it(`should parse pairs/${basename}.csv to match pairs/${basename}.json`, (done) => {
const gold = JSON.parse(readFileSync(`${__dirname}/pairs/${basename}.json`, {encoding: 'utf8'}));
// console.error('JSON>>', json_filename, group);
const stream = createReadStream(`${__dirname}/pairs/${basename}.txt`);
readToEnd(stream.pipe(new Parser()), (err, rows) => {
if (err) return done(err);
deepEqual(rows, gold);
done();
});
});
示例3: it
it('should parse a literal string into some objects', (done) => {
const input = [
'index name time',
'1 chris 1:18',
'2 daniel 1:17',
'3 lewis 1:30',
'4 stephen 1:16',
'5 larry 1:31',
].join('\n');
const parser = new Parser();
readToEnd(parser, (err, rows) => {
ok(rows[2], 'There should be a third row');
equal(rows[2].name, 'lewis', 'The name attribute of the third row should be "lewis"');
done();
});
parser.end(input);
});
示例4: it
it('passthrough', done => {
const input = [
{ index: '1', name: 'chris', time: '1:29' },
{ index: '2', name: 'daniel', time: '1:17' },
{ index: '3', name: 'lewis', time: '1:30' },
{ index: '4', name: 'stephen', time: '1:16' },
{ index: '5', name: 'larry', time: '1:31' },
];
const stringifier = new Stringifier({peek: 2, missing: 'NA'});
const parser = stringifier.pipe(new Parser());
readToEnd(parser, (err, output) => {
deepEqual(output, input, 'Throughput should be transparent.');
done();
});
input.forEach((record) => stringifier.write(record));
stringifier.end();
});