An atok stream

@param {Object=} atok stream options
@constructor
328892
function Atok (options) {
  if (!(this instanceof Atok))
    return new Atok(options)

  // Possible events are defined at instanciation for better performance
  EV.call(this, Atok.events)
  this.writable = true
  this.readable = true

  // Options
  options = options || {}
  this._encoding = null
  if (options.encoding) this.setEncoding( options.encoding )

  // Initializations
  // Debug flag
  this.debugMode = false

  // Status flags
  this.ended = false        // Flag indicating stream has ended
  this.ending = false       // Set when end() invokes write()
  this.paused = false       // Flag indicating stream is paused
  this.needDrain = false    // Flag indicating stream needs drain

// include("Atok_properties.js")
  // Public properties
  this.buffer = null
  this.length = 0
  this.offset = 0
  this.markedOffset = -1    // Flag indicating whether the buffer should be kept when write() ends

  // Private properties
  this._firstRule = null        // Initial rule to be triggered
  this._resetRule = false       // Rule set was changed
  this._stringDecoder = this._encoding ? new StringDecoder(this._encoding) : null
  this._rulesToResolve = false  // Rules need to be resolved (continue() prop)
  this._rulesToLink = false     // Rules need to be relinked (after a rule set change)
  this._group = -1
  this._groupStart = 0
  this._groupEnd = 0
  this._groupStartPrev = []


    this._rules = []              // Rules to be checked against
    this._defaultHandler = null   // Matched token default handler
    this._savedRules = {}         // Saved rules

// include("Atok_rule_properties.js")
  this._p_ignore = false        // Get the token size and skip
  this._p_quiet = false         // Get the token size and call the handler with no data
  this._p_escape = false        // Pattern must not be escaped
  this._p_trimLeft = true       // Remove the left pattern from the token
  this._p_trimRight = true      // Remove the right pattern from the token
  this._p_next = null           // Next rule to load
  this._p_nextIndex = 0         // Index for the next rule to load
  this._p_continue = null       // Next rule index to load
  this._p_continueOnFail = null // Next rule index to load when rule fails
  this._p_break = false         // Abort current rule set

  this._defaultProps = Object.keys(this)
    .filter(function (prop) {
      return /^_p_/.test(prop) && !/(continueOnFail|nextIndex)$/.test(prop)
    })
    .map(function (prop) {
      return prop.substr(3)
    })
}
800216
function(cb) {
          var opts = {
            url: uri + 'user/stream',
            method: 'GET',
            qs: qs,
            json: true
          };
          request(opts,function(e,r,b) {
            if (e) cb(e)
            else {
              if (r.statusCode==200) cb(null, b)
              else {
                cb({statusCode:r.statusCode,error:b.error})
              }
            }
          });
        }
952129
function TapReceiver(streamOptions) {
    Writable.call(this, streamOptions);
    this._aborting = false;
    this._tapParser = new TapParser();
    this._setupParser(this._tapParser);
}
521360
function stream (input, value) {
  value.on('data', data => input.push(data))
  value.on('error', err => error(input, err))
  value.on('end', () => input.push(null))
}
31544
function object (input, value) {
  if (value instanceof Stream) stream(input, value)
  else stringify(input, value)
}
535923
function stream(opts) {
  opts = lo.isObject(opts) ? opts : {}
  config.input = opts.input || process.stdin
  config.output = opts.output || process.stdout
}
660199
function WritableUSBStream(endpoint, options)
{
	options = options || {};
	options.decodeStrings = false;
	stream.Writable.call(this, options);

	this.paused = false;

	this.endpoint = endpoint;
	this.endpoint.addListener('drain', this.onDrain.bind(this));
	this.endpoint.addListener('error', this.onError.bind(this));
	this.endpoint.addListener('end', this.onEnd.bind(this));

	this.endpoint.startStream(3, 64);
}
417502
function OSMStream(options) {
  if (!(this instanceof OSMStream)) return new OSMStream(options);

  Transform.call(this, options);

  var primaryElements = ['node', 'way', 'relation']; // emit-ables
  var subElementName = ['tag', 'nd', 'member'];

  // size of bytes read from source so far
  this.bytesRead = 0;
  // size of bytes written to stream so far
  this.bytesWritten = 0;

  // initialize parser and its event handlers
  this._parser = new expat.Parser();

  this._parser.on('pipe', (function onParserPipe(src) {
    logger('_parser received pipe from ', src.path || '<unknown pipe>');
  }).bind(this));

  this._parser.on('startElement', (function onParserStartElement(name, attrs) {
    var funcname = ['__parse_', name].join('');
    if ((primaryElements.indexOf(name) > -1 && (OSMStream.prototype[funcname])) ||
      (subElementName.indexOf(name) > -1 && this._currentElement !== null && (OSMStream.prototype[funcname]))) {
      OSMStream.prototype[funcname].call(this, attrs);
    }
  }).bind(this));

  this._parser.on('endElement', (function onParserEndElement(name) {
    if ((primaryElements.indexOf(name) < 0)) return;

    var clone = extend({}, this._currentElement);
    this._currentElement = null;

    var pushData = function pushData(data) {
      if (!data) return;

      if (this.listeners('writeable').length > 0) {
        this.emit('writeable', data, (function onWriteable(data) {
          this.__push(data);
        }).bind(this));
      } else {
        this.__push(data);
      }

    }.bind(this);

    if (this.listeners(name).length > 0) {
      this.emit(name, clone, (function onElement(data) {
        pushData(data);
      }.bind(this)));
    } else {
      pushData(clone);
    }
  }).bind(this));

  this._parser.on('error', (function onParserError(err) {
    this.emit('error', err);
  }).bind(this));

  this._parser.on('end', (function onParserEnd() {
  }).bind(this));

  this.on('pipe', (function onPipe(src) {
    if (src === this._parser) return;
    // attaching stream pipe to parser
    logger('Received pipe from ', src.toString(), ', attaching pipe to _parser');
    src.pipe(this._parser);
    this._parser.pipe(this);
  }).bind(this));

}
791530
function(stream, post) {
  this._credentials = [];
  this._status      = {};
  this._modules = {
    stream:   stream   || Stream,
    post:     post     || Post
  };
}
1129446
function RowStream(statement, context, options)
{
  // validate non-user-specified arguments
  Errors.assertInternal(Util.exists(statement));
  Errors.assertInternal(Util.exists(context));

  // call Readable constructor
  Readable.call(this,
  {
    objectMode    : true,
    highWaterMark : context.connectionConfig.getRowStreamHighWaterMark()
  });

  // extract streaming options
  var start, end, fetchAsString;
  if (Util.isObject(options))
  {
    start         = options.start;
    end           = options.end;
    fetchAsString = options.fetchAsString;
  }

  // if a fetchAsString value is not specified in the stream options, try the
  // statement and connection options (in that order)
  if (!Util.exists(fetchAsString))
  {
    fetchAsString = context.fetchAsString;
  }
  if (!Util.exists(fetchAsString))
  {
    fetchAsString = context.connectionConfig.getFetchAsString();
  }

  var resultStream = null, numResultStreamInterrupts = 0;
  var rowBuffer = null, rowIndex = 0;
  var columns, mapColumnIdToExtractFnName;
  var initialized = false;

  var self = this;

  /**
   * Reads the next row in the result.
   *
   * @private
   */
  this._read = function()
  {
    // if the stream has been initialized, just read the next row
    if (initialized)
    {
      readNextRow();
    }
    // if we're still fetching the result, wait for the operation to complete
    else if (context.isFetchingResult)
    {
      context.on('statement-complete', init);
    }
    // if we have a result or a fatal error, call init() in the next tick of
    // the event loop
    else if (context.result || isStatementErrorFatal(context.resultError))
    {
      process.nextTick(init);
    }
    else
    {
      // fetch the result again and call init() upon completion of the operation
      context.refresh(init);
    }
  };

  /**
   * Initializes this stream.
   */
  var init = function init()
  {
    // the stream has now been initialized
    initialized = true;

    // if we have a result
    if (context.result)
    {
      // if no value was specified for the start index or if the specified start
      // index is negative, default to 0, otherwise truncate the fractional part
      start = (!Util.isNumber(start) || (start < 0)) ? 0 : Math.floor(start);

      // if no value was specified for the end index or if the end index is
      // larger than the row index of the last row, default to the index of the
      // last row, otherwise truncate the fractional part
      var returnedRows = context.result.getReturnedRows();
      end = (!Util.isNumber(end) || (end >= returnedRows)) ? returnedRows - 1 :
          Math.floor(end);

      // find all the chunks that overlap with the specified range
      var overlappingChunks = context.result.findOverlappingChunks(start, end);

      // if no chunks overlap or start is greater than end, we're done
      if ((overlappingChunks.length === 0) || (start > end))
      {
        process.nextTick(close);
      }
      else
      {
        // create a result stream from the overlapping chunks
        resultStream = new ResultStream(
        {
          chunks       : overlappingChunks,
          prefetchSize : context.connectionConfig.getResultPrefetch()
        });

        readNextRow();
      }
    }
    else
    {
      close(context.resultError);
    }
  };

  /**
   * Processes the row buffer.
   */
  var processRowBuffer = function processRowBuffer()
  {
    // get the row to add to the read queue
    var row = rowBuffer[rowIndex++];

    // if we just read the last row in the row buffer, clear the row buffer and
    // reset the row index so that we load the next chunk in the result stream
    // when _read() is called
    if (rowIndex === rowBuffer.length)
    {
      rowBuffer = null;
      rowIndex = 0;
    }

    // initialize the columns and column-related maps if necessary
    if (!columns)
    {
      columns = statement.getColumns();
    }
    if (!mapColumnIdToExtractFnName)
    {
      mapColumnIdToExtractFnName =
          buildMapColumnExtractFnNames(columns, fetchAsString);
    }

    // add the next row to the read queue
    process.nextTick(function()
    {
      self.push(externalizeRow(row, columns, mapColumnIdToExtractFnName));
    });
  };

  /**
   * Called when the result stream reads a new chunk.
   *
   * @param {Chunk} chunk
   */
  var onResultStreamData = function onResultStreamData(chunk)
  {
    // unsubscribe from the result stream's 'data' and 'close' events
    resultStream.removeListener('data', onResultStreamData);
    resultStream.removeListener('close', onResultStreamClose);

    // get all the rows in the chunk that overlap with the requested window,
    // and use the resulting array as the new row buffer
    var chunkStart = chunk.getStartIndex();
    var chunkEnd = chunk.getEndIndex();
    rowBuffer = chunk.getRows().slice(
        Math.max(chunkStart, start) - chunkStart,
        Math.min(chunkEnd, end) + 1 - chunkStart);

    // reset the row index
    rowIndex = 0;

    // process the row buffer
    processRowBuffer();
  };

  /**
   * Called when there are no more chunks to read in the result stream or an
   * error is encountered while trying to read the next chunk.
   *
   * @param err
   * @param continueCallback
   */
  var onResultStreamClose = function onResultStreamClose(err, continueCallback)
  {
    // if the error is retryable and
    // the result stream hasn't been closed too many times
    if (isResultStreamErrorRetryable(err) &&
        (numResultStreamInterrupts <
        context.connectionConfig.getResultStreamInterrupts()))
    {
      numResultStreamInterrupts++;

      // fetch the statement result again
      context.refresh(function()
      {
        if (context.resultError)
        {
          close(context.resultError);
        }
        else
        {
          continueCallback();
        }
      });
    }
    else
    {
      close(err);
    }
  };

  /**
   * Closes the row stream.
   *
   * @param {Error} [err]
   */
  var close = function(err)
  {
    // if we have a result stream, stop listening to events on it
    if (resultStream)
    {
      resultStream.removeListener('data', onResultStreamData);
      resultStream.removeListener('close', onResultStreamClose);
    }

    // we're done, so time to clean up
    rowBuffer = null;
    rowIndex = 0;
    resultStream = null;
    numResultStreamInterrupts = 0;

    if (err)
    {
      emitError(err);
    }
    else
    {
      self.push(null);
    }
  };

  /**
   * Called when we're ready to read the next row in the result.
   */
  var readNextRow = function readNextRow()
  {
    // if we have a row buffer, process it
    if (rowBuffer)
    {
      processRowBuffer();
    }
    else
    {
      // subscribe to the result stream's 'data' and 'close' events
      resultStream.on('data', onResultStreamData);
      resultStream.on('close', onResultStreamClose);

      // issue a request to fetch the next chunk in the result stream
      resultStream.read();
    }
  };

  /**
   * Externalizes an error and emits it.
   *
   * @param {Error} err
   */
  var emitError = function emitError(err)
  {
    self.emit('error', Errors.externalize(err));
  };
}
205619
function FileInputStream(src){
    // wrap into Promise
    return new Promise(function(resolve, reject){

         // 
        const istream = _fs.createReadStream(src);
        istream.on('error', reject);
        istream.on('open', function(){
            resolve(istream);
        });
    });
}
719150
function streamOn(name, fn) {
        var str,
            handle;
        if (typeof name === 'string') {
            str = name;
            name = {
                test: function (val) {
                    return val === str;
                }
            };
        }
        /**
         * @callback {EventStream.handle}
         * @param chunk
         * @type {function}
         */
        handle = function (chunk) {
            if (name.test(chunk.name)) {
                fn(chunk.data);
            }
        };
        this.eventStreamListeners.push(handle);
        return handle;
    }
920777
function StreamCopier() {
	var self = this
	stream.Stream.call(this)
	this.writable = true
	this.log = log
	this.write = write
	this.setPrepend = setPrepend
	this.pLog = pLog
	this.addStream = addStream
	this.removeStream = removeStream
	this.end = end
	this.destroy = destroy
	var prepend
	var streamIndex = 0
	var streams = {}

	function pLog() {
		commonLog(Array.prototype.slice.call(arguments), prepend)
	}

	function log() {
		commonLog(Array.prototype.slice.call(arguments))
	}

	function commonLog(args, prepend) {
		var s = util.format.apply(this, args) + '\n'
		if (prepend) s = prepend + ' ' + s
		write(s)
	}

	function setPrepend(s) {
		prepend = s ? String(s) : ''
		return self
	}

	function addStream(stream, name) {
		if (self.writable) {
			var i = streamIndex++
			streams[i] = {
				stream: stream,
				name: name
			}
		} else self.emit('error', 'Stream not writable')
		return i
	}

	function removeStream(no) {
		delete streams[no]
	}

	function write(s) {
		var err
		var didCb
		var args = Array.prototype.slice.call(arguments)
		var cb = typeof args[args.length - 1] === 'function' ? args.pop() : null

		var cbCounter = Object.keys(streams).length + 1
		for (var streamNo in streams) doWrite(streamNo)
		end()

		function doWrite(streamNo) {
			var stream = streams[streamNo].stream
			if (stream.writable) stream.write.apply(stream, args.concat(writeResult))
			else streamLost()

			function writeResult(e) {
				if (!e) end()
				else streamLost(e) // a write resulted in error
			}

			function streamLost(e) {
				var isError = Object.keys(streams).length == 1 // if we lost the last stream, it's error

				// emit the event
				eventType = isError ? 'error' : 'warning'
				var msg = 'Stream ' + streams[streamNo].name + ' no longer writable'
				if (e) msg += ': ' + err.msg
				self.emit(eventType, msg)
				delete streams[streamNo]

				if (isError) {
					if (!e) e = new Error(msg)
					self.writable = false
					end(e)
				} else write(msg, end) // write to remaining streams
			}
		}

		function end(e) {
			if (!err && e) err = e
			if (!err) {
				if (!--cbCounter && cb) {
					cb()
				}
			} else if (!didCb && cb) {
				didCb = true
				cb(err)
			}
		}
	}

	function end(s) {
		var err
		var args = Array.prototype.slice.call(arguments)
		var cb = typeof args[args.length - 1] === 'function' ? args.pop() : null
		var cbCounter = Object.keys(streams).length + 1

		if (args.length) write.apply(this, args.concat(allWritten))
		else allWritten()

		function allWritten(e) {
			if (e && !err) err = e
			for (var streamNo in streams) doEnd(streamNo)
			end()
		}

		function doEnd(streamNo) {
			streams[streamNo].stream.end(endResult)

			function endResult(e) {
				if (e) {
					if (!err) err = e
					self.emit('error', 'Stream ' + streams[streamNo].name + ' end error: ' + e.message)
				}
				delete streams[streamNo]
				end()
			}
		}

		function end() {
			if (!--cbCounter) {
				self.writable = false
				if (cb)
					if (err) cb(err)
					else cb()
			}
		}
	}

	function destroy(cb) {
		var cbCounter = Object.keys(streams).length + 1
		for (var streamNo in streams) doDestroy(streamNo)
		end()

		function doDestroy(streamNo) {
			streams[streamNo].stream.destroy(endResult)

			function destroyResult(e) {
				if (e) {
					if (!err) err = e
					self.emit('error', 'Stream ' + streams[streamNo].name + ' destroy error: ' + e.message)
				}
				delete streams[streamNo]
				end()
			}
		}

		function end() {
			if (!--cbCounter) {
				self.writable = false
				if (cb)
					if (err) cb(err)
					else cb()
			}
		}
	}
}
1122658
function create(options) {
  options = options || {};

  var scrollParent = (options.scrollTarget && options.scrollTarget.parentNode) || window;

  var oldScrollY;
  var scrollDirty = true;
  var scrollEventsStream = Stream.createFromEvents(scrollParent, 'scroll');

  Stream.onValue(scrollEventsStream, function onScrollSetDirtyBit_() {
    scrollDirty = true;
  });

  var rAF = Stream.createFromRAF();

  var didChangeOnRAFStream = Stream.filter(function filterDirtyFramesFromRAF_() {
    if (!scrollDirty) { return false; }
    scrollDirty = false;

    var newScrollY = DOM.documentScrollY(scrollParent);

    if (oldScrollY !== newScrollY) {
      oldScrollY = newScrollY;
      return true;
    }

    return false;
  }, rAF);

  // It's going to space, will you just give it a second!
  Util.defer(Util.partial(Events.dispatchEvent, scrollParent, 'scroll'), 10);

  return Stream.map(function getWindowPosition_() {
    return oldScrollY;
  }, didChangeOnRAFStream);
}
551649
function httpOk(req, res, content, fileExt) {
    res.writeHead(200, {
        'Content-Type': Mine.getType(fileExt),
    });
    res.write(content, 'binary');
    res.end();
}
1191496
function toStream(input) {
  let streamType = isStream(input);
  if (streamType === 'node') {
    return nodeToWeb(input);
  } else if (streamType) {
    return input;
  }
  return new ReadableStream({
    start(controller) {
      controller.enqueue(input);
      controller.close();
    }
  });
}
1154819
function handle_stream_error(stream) {
    return stream.on('error', function (/*error*/) {
        // console.error(error);
        $.util.log.apply(this, arguments);
        stream.end();
    });
}