當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。