0

私はこのライブラリで作業しています: mTwitter

私の問題は、ストリーミング機能を使用したいときです:

twit.stream.raw(
  'GET',
  'https://stream.twitter.com/1.1/statuses/sample.json',
  {delimited: 'length'},
    process.stdout  
);

を生成する JSON にアクセスする方法がわかりませんprocess.stdout

4

2 に答える 2

1

からの書き込み可能なストリームを使用できますstream.Writable

var stream = require('stream');
var fs = require('fs');

// This is where we will be "writing" the twitter stream to.
var writable = new stream.Writable();

// We listen for when the `pipe` method is called. I'm willing to bet that
// `twit.stream.raw` pipes to stream to a writable stream.
writable.on('pipe', function (src) {

  // We listen for when data is being read.
  src.on('data', function (data) {
    // Everything should be in the `data` parameter.
  });

  // Wrap things up when the reader is done.
  src.on('end', function () {
    // Do stuff when the stream ends.
  });

});

twit.stream.raw(
  'GET',
  'https://stream.twitter.com/1.1/statuses/sample.json',
  {delimited: 'length'},

  // Instead of `process.stdout`, you would pipe to `writable`.
  writable
);
于 2013-10-24T17:50:37.637 に答える