当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript streaming.readToEnd函数代码示例

本文整理汇总了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});
  });
}
开发者ID:chbrown,项目名称:twilight,代码行数:14,代码来源:credentials.ts

示例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();
   });
 });
开发者ID:chbrown,项目名称:sv,代码行数:10,代码来源:pairs.ts

示例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);
  });
开发者ID:chbrown,项目名称:sv,代码行数:18,代码来源:basic.ts

示例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();
  });
开发者ID:chbrown,项目名称:sv,代码行数:20,代码来源:throughput.ts


注:本文中的streaming.readToEnd函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。