Manages the streaming connection to Wordpress
@constructor
@extends Stream
421172
function(service, credentials, accounts, keywords) {
  Stream.call(this, service, credentials, accounts, keywords);
  
  // Initialize responder
  this.responder = new Responder();
  
}
450798
function Stream(trackSubscribers, buffer) {
  if (!(this instanceof Stream)) {
    return new Stream(trackSubscribers, buffer);
  }

  this.trackSubscribers = !!trackSubscribers;
  this.subscribers = null;
  this.subscriberSubscribers = null;
  this.streamID = nextID++;
  this.values = Util.isDefined(buffer) ? buffer : Buffer.create(1, 'sliding');
  this.closed = false;
  this.closeSubscribers = null;
  this.emptySubscribers = null;

  openStreams[this.streamID] = this;
}
1242979
function getWebsiteStream(start, options) {
  var highWaterMark = 2;
  if (options && options.highWaterMark) {
    highWaterMark = options.highWaterMark;
  } else if (options && options.parallel) {
    highWaterMark = options.parallel + 1;
  }
  var stream = new Readable({
    objectMode: true,
    highWaterMark: highWaterMark
  });

  var downloaded = {};
  function handleUri(uri, push) {
    uri = uri.split('#')[0];
    if (downloaded[uri] === true || !isHttp(uri) || !filter(options, uri)) {
      return Promise.resolve(null);
    }
    downloaded[uri] = true;
    return download(uri).then(function (result) {
      result.dependencies.forEach(function (dependency) {
        push(url.resolve(uri, dependency));
      });
      return result;
    });
  }

  var queue = Array.isArray(start) ? start : [start];
  var finished = false;
  var inProgress = 0;
  function process(session) {
    if (inProgress === 0 && !finished && queue.length === 0) {
      finished = true;
      stream.push(null);
    }
    if (queue.length === 0) {
      return;
    }
    inProgress++;
    return handleUri(queue.shift(), queue.push.bind(queue)).done(function (result) {
      inProgress--;
      if (finished) return;
      if (result !== null) {
        if (stream.push(result) && session.live) {
          process(session);
        } else {
          session.live = false;
        }
      } else if (session.live) {
        process(session);
      }
    }, function (err) {
      inProgress--;
      if (finished) return;
      finished = true;
      stream.emit('error', err);
      stream.push(null);
    });
  }

  var session = {live: false};
  stream._read = function () {
    if (session.live) return;
    session = {live: true};
    if (options && options.parallel) {
      for (var i = 0; i < options.parallel; i++) {
        process(session);
      }
    } else {
      process(session);
    }
  };

  return stream;
}
595109
function (stream, close) {
                this._stream = stream;
                if (typeof close === "function") {
                    this._close = close;
                }
                stream.on("error", this._onError.bind(this));
            }
765877
function Stream (options) {

  //check options
  if (!options) {

    throw new Error('Initialization error: missing transport options')
  }

  this._initDefaults() //Initialize default params
  this._updateParams(options)
  this._initTransport(options.transport)

  var self = this

  self.on('error', nop)

  this.subscriptions = []

  this.getSubscriptions = function () {

    return this.subscriptions
  }

  this.addSubscription = function (args, callback) {

    var c = new Subscription(args, callback, this)
    this.subscriptions[c.eid] = c
    return c
  }

  this.getSubscription = function (channel, resource) {

    if (this.subscriptions[channel + this.seperator + resource]) {
      return this.subscriptions[channel + this.seperator + resource]
    }
    return null
  }

  this.getAnySubscription = function (channel, resource) {

    if (this.subscriptions[channel + this.seperator + resource]) {
      return this.subscriptions[channel + this.seperator + resource]
    } else if (this.subscriptions[channel + this.seperator + this.wildcard]) {
      return this.subscriptions[channel + this.seperator + this.wildcard]
    } else {
      return null
    }
  }

  this.removeSubscription = function (channel, resource) {

    resource = resource || this.wildcard
    if (this.subscriptions[channel + this.seperator + resource]) {
      var retval = this.subscriptions[channel + this.seperator + resource]
      delete this.subscriptions[channel + this.seperator + resource]
      return retval
    }

    return null
  }

  this.getSubscriptionWithPermission = function (channel, resource, read, write) {

    var Subscription = this.subscriptions[channel + this.seperator + resource]
    var match = false

    if (Subscription) {

      match = true

      if (read) {
        match = Subscription.hasReadPermission()
      }

      if (write) {
        match = Subscription.hasWritePermission()
      }

      if (match) {
        return Subscription
      }
    } else {

      Subscription = this.subscriptions[channel + this.seperator + this.wildcard]

      if (Subscription) {

        match = true

        if (read) {
          match = Subscription.hasReadPermission()
        }

        if (write) {
          match = Subscription.hasWritePermission()
        }

        if (match) {
          return Subscription
        }
      }
    }

    return null
  }

  this.connection = new this.ConnectionFactory(this)
  this.connect()
}
416305
function ServerClientStream(app){
    var StreamHandler;
    app.use(function(req, res, next){
      if(req.originalUrl == '/promise-pipe-connector' && req.method=='POST'){
        var message = req.body;
        message._response = res;
        StreamHandler(message)
      } else {
        return next();
      }
    });
    return {
      send: function(message){
        if(!message._response) throw Error("no response defined");
        var res = message._response;
        message._response = undefined;
        res.json(message);
      },
      listen: function(handler){
        StreamHandler = handler;
      }
    }
  }
1064579
protected function checkStream()
    {
        // Find document content type
        while ( !feof( $this->stream ) )
        {
            $line = fgets( $this->stream );

            // Check if we found a new document definition
            if ( !preg_match( '(^Content-Type:\\s+(?P<type>[a-z*][a-z0-9_/*+.-]*)(;\s*(?P<options>.*))?$)', trim( $line ), $match ) )
            {
                continue;
            }

            $type    = $match['type'];
            $options = isset( $match['options'] ) ? preg_split( '(\s*;\s*)', $match['options'] ) : array();
            foreach ( $options as $option )
            {
                if ( preg_match( '(^(?P<key>[a-z-]+)=("?)(?P<value>.*?)\\2$)', $option, $match ) )
                {
                    $this->options[$match['key']] = $match['value'];
                }
            }

            if ( $type !== 'multipart/mixed' )
            {
                throw new phpillowMultipartParserException( 'This handler does only understand "multipart/mixed" documents.' );
            }

            break;
        }

        // Search for first starting boundary
        while ( !feof( $this->stream ) )
        {
            if ( trim( fgets( $this->stream ) ) === '--' . $this->options['boundary'] )
            {
                break;
            }
        }
    }
77476
function viewStream(view) {
  return function() {
    var stream = utils.through.obj();
    stream.setMaxListeners(0);
    setImmediate(function(item) {
      stream.write(item);
      stream.end();
    }, this);
    return outStream(stream, view);
  };
}
1072251
function(connect) {
		var obs = this._observer;
		if (obs) {
			if (connect) {
				obs.observe(document, {
					childList: true,
					subtree: true
				});
			} else {
				obs.disconnect();
			}
		}
	}
539298
function() {
  /**
   * Protobuf raw bytes stream parser
   * @private {?JsonStreamParser}
   */
  this.jsonStreamParser_ = null;

  /**
   * The current error message, if any.
   * @private {?string}
   */
  this.errorMessage_ = null;

  /**
   * The current position in the streamed data.
   * @private {number}
   */
  this.streamPos_ = 0;

  /**
   * The current parser state.
   * @private {!State}
   */
  this.state_ = State.INIT;

  /**
   * The currently buffered result (parsed JSON objects).
   * @private {!Array<!Object>}
   */
  this.result_ = [];

  /**
   * Whether the status has been parsed.
   * @private {boolean}
   */
  this.statusParsed_ = false;
}
1058129
function streamOutput( callback ) {
	return function(err, filenames) {
		if (err) {
			callback(err, null);
		} else {
			// Create read streams from each input
			var streams = []
			for (var i=0; i<filenames.suffix.length; i++)
				streams.push([
					fs.createReadStream( filenames.basename + filenames.suffix[i]),
					filenames.suffix[i]
				]);
			// Callback with streams
			callback(err, streams);
		}
	}
}
502375
function onConnection() {
  var endpoint = new http2.Endpoint(log, 'CLIENT', {});
  endpoint.pipe(socket).pipe(endpoint);

  // Sending request
  var stream = endpoint.createStream();
  stream.headers({
    ':method': 'GET',
    ':scheme': url.protocol.slice(0, url.protocol.length - 1),
    ':authority': url.hostname,
    ':path': url.path + (url.hash || '')
  });

  // Receiving push streams
  stream.on('promise', function(push_stream, req_headers) {
    var filename = path.join(__dirname, '/push-' + push_count);
    push_count += 1;
    console.error('Receiving pushed resource: ' + req_headers[':path'] + ' -> ' + filename);
    push_stream.pipe(fs.createWriteStream(filename)).on('finish', finish);
  });

  // Receiving the response body
  stream.pipe(process.stdout);
  stream.on('end', finish);
}
360012
function Stream(i) {
	this.offset = 0;
	if (i instanceof Buffer) {
		this.buffer = i;
	}
	else {
		this.buffer = new Buffer(i || 8192);
	}
}
862974
function send(stream) {
      res.setHeader('content-type', mimetype);

      if (config.setCacheControl && !isNaN(config.maxAge)) {
        res.setHeader('Cache-Control', `public, max-age=${Math.floor(config.maxAge / 1000)}`)
      }

      if (config.beforeSend === 'function') {
        config.beforeSend(res, stream);
      }
      
      stream2buffer(stream, (err, buffer) => {
        if (err) {
          // faild to convert to buffer so lets just stream it.
          res.status(500).send('Internal Server Error');
          return;
        }
        
        const eTag = etag(buffer);
        const headers = req.headers;
        
        if (headers['if-none-match'] && headers['if-none-match'].replace('"', '') === eTag) {
          res.status(304);
          res.setHeader('ETag', eTag);
          res.setHeader('Content-Length', 0);
          res.end();
          return;
        }
        
        res.setHeader('ETag', eTag);

        res.send(buffer);
      });
    }
321661
public function stream()
    {
        $endpoint = $this->getEndpoint();
        $params = $this->getParams();
        $list = $this->getClient()->request($endpoint, 'GET', $params);
        foreach ($list['items'] as $item) {
            yield $item;
        }

        while ($list['metadata']['continue']) {
            $params['continue'] = $list['metadata']['continue'];
            $list = $this->getClient()->request($endpoint, 'GET', $params);
            foreach ($list['items'] as $item) {
                yield $item;
            }
        }
    }
737912
function fetchStream() {
	var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
	var callback = arguments[1];

	var cb = callback;
	var stream = null;
	if (cb === undefined) {
		stream = makeStream();
		cb = stream.handler;
	}
	var url = typeof options === 'string' ? options : options.url || options.path;
	if (supportFetch) {
		// TODO support Request object?
		var init = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? options : {};
		fetch(url, init).then(function (res) {
			if (res.status >= 200 && res.status < 300) {
				pump(res.body.getReader(), (0, _parser2.default)(cb));
			} else {
				// TODO read custom error payload
				cb(null, { status: res.status, statusText: res.statusText });
			}
		}, function (err) {
			cb(null, err);
		});
	} else {
		(function () {
			var parser = (0, _parser2.default)(cb, _parser.BUFFER);
			var opts = (typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object' ? _extends({}, options) : {};
			opts.path = url;
			var req = _streamHttp2.default.get(opts, function (res) {
				var status = res.status || res.statusCode;
				if (!(status >= 200 && status < 300)) {
					// TODO read custom error payload
					cb(null, { status: status, statusText: res.statusText || res.statusMessage });
					return;
				}

				res.on('data', function (buf) {
					if (parser(buf) === false) {
						// cancelling
						req.abort();
					}
				});

				res.on('error', function (err) {
					req.abort();
					cb(null, err);
				});
			});
		})();
	}
	return stream;
}
1314092
function stream(out, err) {
  if(!err) err = out;

  if(typeof out === 'string') {
    this._out = fs.createWriteStream(out);
  }else{
    this._out = out;
  }

  if(typeof err === 'string') {
    this._err = fs.createWriteStream(err);
  }else{
    this._err = err;
  }

  if((!(this._out instanceof Writable)
      && this._out !== process.stdout)
    || (!(this._err instanceof Writable)
      && this._err !== process.stderr)) {
    throw new Error('invalid log stream');
  }
}