Initialize a readable stream. This is used for both the readable and duplex
stream constructors.
@private
@param {Readable} stream The stream to initialize
@param {grpc~deserialize} deserialize Deserialization function for
incoming data.
354271
function setUpReadable(stream, deserialize) {
  stream.deserialize = common.wrapIgnoreNull(deserialize);
  stream.finished = false;
  stream.reading = false;

  stream.terminate = function() {
    stream.finished = true;
    stream.on('data', function() {});
  };

  stream.on('cancelled', function() {
    stream.terminate();
  });
}
1315849
function Stream(log, connection) {
  Duplex.call(this);

  // * logging
  this._log = log.child({ component: 'stream', s: this });

  // * receiving and sending stream management commands
  this._initializeManagement();

  // * sending and receiving frames to/from the upstream connection
  this._initializeDataFlow();

  // * maintaining the state of the stream (idle, open, closed, etc.) and error detection
  this._initializeState();

  this.connection = connection;
}
308551
function isReadableStream (stream) {
  return stream !== null
    && typeof (stream) === 'object'
    && typeof (stream.pipe) === 'function'
    && typeof (stream._read) === 'function'
    && typeof (stream._readableState) === 'object'
    && stream.readable !== false
}
717210
function _createStreamPointer(self, stream, serializer) {
  let id = uuid();
  let readable = typeof stream.read === 'function';
  let type = readable ? 'readable' : 'writable';
  let pointer = `boscar:${type}:${id}`;

  self.streams.set(id, stream);

  if (readable) {
    _bindReadable(pointer, stream, serializer);
  }

  return pointer;
}
500641
function Parser(stream) {
  StreamStack.call(this, stream, {
    data: function(b) { this._onData(b); }
  });
  this._onData = this._parseHeader;
  this._headerParser = new HeaderParser(new Stream(), {
    emitFirstLine: false,
    strictCRLF: false,
    strictSpaceAfterColon: false,
    allowFoldedHeaders: false
  });
  this._headerParser.on('headers', this._onHeadersComplete.bind(this));
}
894562
function __deserializeObjectStreaming(buffer, start, options) {
	let end = start;
	let dataView = new DataView(buffer);
	let endData = new Uint16Array(TYPE_HEADER.OBJECT_END);
	let data = {};
	while (start < buffer.byteLength) {
		let tmpType = dataView.getUint16(start, true);
		if (tmpType === endData[0]) {
			end += 2;
			break;
		}

		let subType, subKey, subData;
		({ anchor: start, value: subType } = __deserializeType(buffer, start, options));
		({ anchor: start, value: subKey } = __deserializeShortString(buffer, start, options));
		({ anchor: start, value: subData } = __deserializeData(subType, buffer, start, options));
		data[subKey] = subData;
		end = start;
	}
	return { anchor: end, value: data };
}
1037000
function StreamReader(read) {

	var tail = '', messages = new Array();

	/**
	 * Parsa new data.
	 * @param {String} data New data from the stream
	 */
	function parse(data, initExpected) {
		var lines, i, last;
		data = tail + data;
		data = data.replace(/\r*\n+/g, "\n");
		lines = data.split("\n");
		last = lines.length - 1;
		for (i = 0; i < last; i++) {
			messages.push(read(lines[i], initExpected));
		}
		tail = lines[lines.length - 1];
	}

	/**
	 * Pop the next message
	 */
	function pop() {
		return messages.shift();
  	}

	/**
	 * Return if it has no more messages
	 */
	function isEmpty() {
		return messages.length == 0;
  	}

	// Public methods
	that = {
		parse: parse,
		pop: pop,
		isEmpty: isEmpty
	};


	return that;
}
926040
function BufferStreamReader (data, options) {
  if (!(this instanceof BufferStreamReader)) {
    return new BufferStreamReader(data);
  }

  if (!options) {
    options = {};
  }

  stream.Readable.call(this, options);

  this._data = null;
  this._chunkSize = options.chunkSize || -1;

  if (typeof data === 'string') {
    this._data = new Buffer(data, options.encoding || 'utf8');
  } else if (Buffer.isBuffer(data)) {
    this._data = data;
  }
}
196356
private void loadStream(InputStream stream)
    {
        int            iPos       = -1;
        String         strLine    = null;
        String         strSection = null;
        String         strRemarks = null;
        BufferedReader objBRdr    = null;
        InputStreamReader     objFRdr    = null;
        INISection     objSec     = null;

        try
        {
            objFRdr = new InputStreamReader(stream);
            if (objFRdr != null)
            {
                objBRdr = new BufferedReader(objFRdr);
                if (objBRdr != null)
                {
                    while (objBRdr.ready())
                    {
                        iPos = -1;
                        strLine  = null;
                        strLine = objBRdr.readLine().trim();
                        if (strLine == null)
                        {
                        }
                        else if (strLine.length() == 0)
                        {
                        }
                        else if (strLine.substring(0, 1).equals(";"))
                        {
                            if (strRemarks == null)
                                strRemarks = strLine.substring(1);
                            else if (strRemarks.length() == 0)
                                strRemarks = strLine.substring(1);
                            else
                                strRemarks = strRemarks + "\r\n" + strLine.substring(1);
                        }
                        else if (strLine.startsWith("[") && strLine.endsWith("]"))
                        {
                            // Section start reached create new section
                            if (objSec != null) 
                                this.mhmapSections.put(strSection.trim(), objSec);
                            objSec = null;
                            strSection = strLine.substring(1, strLine.length() - 1);
                            objSec = new INISection(strSection.trim(), strRemarks);
                            strRemarks = null;
                        }
                        else if ((iPos = strLine.indexOf("=")) > 0 && objSec != null)
                        {
                            // read the key value pair 012345=789
                            objSec.setProperty(strLine.substring(0, iPos).trim(), 
                                                strLine.substring(iPos + 1).trim(), 
                                                strRemarks);
                            strRemarks = null;
                        }
                        else 
                        {
                            objSec.setProperty(strLine, "", strRemarks);
                      
                        }
                    }
                    if (objSec != null)
                        this.mhmapSections.put(strSection.trim(), objSec);
                    this.mblnLoaded = true;
                }
            }
        }
        catch (FileNotFoundException FNFExIgnore)
        {
            this.mhmapSections.clear();
        }
        catch (IOException IOExIgnore)
        {
            this.mhmapSections.clear();
        }
        catch (NullPointerException NPExIgnore)
        {
            this.mhmapSections.clear();
        }
        finally
        {
            if (objBRdr != null)
            {
                closeReader(objBRdr);
                objBRdr = null;
            }
            if (objFRdr != null)
            {
                closeReader(objFRdr);
                objFRdr = null;
            }
            if (objSec != null) objSec = null;
        }
    }
857047
function consumeStream(stream, callback) {
    var chunks = [];
    stream.on("data", onData);
    stream.on("end", onEnd);
    stream.on("error", onError);
    function onData(chunk) {
        chunks.push(chunk);
    }
    function onEnd() {
        cleanup();
        callback(null, chunks.join(""));
    }
    function onError(err) {
        cleanup();
        callback(err);
    }
    function cleanup() {
        stream.removeListener("data", onData);
        stream.removeListener("end", onEnd);
        stream.removeListener("error", onError);
    }
}
922651
public <T> T read(final InputStream stream, final DataTypeDescriptor<T> descriptor)
			throws Exception {
		if (stream == null) throw new NullPointerException("input");
		if (descriptor == null) throw new NullPointerException("descriptor");

		JsonParser parser = factory.createParser(stream);
		return read(parser, descriptor);
	}
147953
function $stream(ctx, qs, initCB, config) {

    const $p = config.promise;

    // istanbul ignore next:
    // we do not provide code coverage for the Native Bindings specifics
    if (ctx.options.pgNative) {
        return $p.reject(new Error(npm.text.nativeStreaming));
    }
    if (!qs || !qs.constructor || qs.constructor.name !== 'PgQueryStream') {
        // stream object wasn't passed in correctly;
        return $p.reject(new TypeError(npm.text.invalidStream));
    }
    if (qs._reading || qs._closed) {
        // stream object is in the wrong state;
        return $p.reject(new Error(npm.text.invalidStreamState));
    }
    if (typeof initCB !== 'function') {
        // parameter `initCB` must be passed as the initialization callback;
        return $p.reject(new TypeError(npm.text.invalidStreamCB));
    }

    let error = npm.events.query(ctx.options, getContext());

    if (error) {
        error = getError(error);
        npm.events.error(ctx.options, error, getContext());
        return $p.reject(error);
    }

    const stream = ctx.db.client.query(qs);

    stream.on('data', onData);
    stream.on('error', onError);
    stream.on('end', onEnd);

    try {
        initCB.call(this, stream); // the stream must be initialized during the call;
    } catch (e) {
        release();
        error = getError(e);
        npm.events.error(ctx.options, error, getContext());
        return $p.reject(error);
    }

    const start = Date.now();
    let resolve, reject, nRows = 0, cache = [];

    function onData(data) {
        cache.push(data);
        nRows++;
        if (cache.length >= qs.batchSize) {
            notify();
        }
    }

    function onError(e) {
        release();
        stream.close();
        e = getError(e);
        npm.events.error(ctx.options, e, getContext());
        reject(e);
    }

    function onEnd() {
        release();
        notify();
        resolve({
            processed: nRows, // total number of rows processed;
            duration: Date.now() - start // duration, in milliseconds;
        });
    }

    function release() {
        stream.removeListener('data', onData);
        stream.removeListener('error', onError);
        stream.removeListener('end', onEnd);
    }

    function notify() {
        if (cache.length) {
            const context = getContext();
            error = npm.events.receive(ctx.options, cache, undefined, context);
            cache = [];
            if (error) {
                onError(error);
            }
        }
    }

    function getError(e) {
        return e instanceof npm.utils.InternalError ? e.error : e;
    }

    function getContext() {
        let client;
        if (ctx.db) {
            client = ctx.db.client;
        } else {
            error = new Error(npm.text.looseQuery);
        }
        return {
            client,
            dc: ctx.dc,
            query: qs.cursor.text,
            params: qs.cursor.values,
            ctx: ctx.ctx
        };
    }

    return $p((res, rej) => {
        resolve = res;
        reject = rej;
    });

}
664514
function (stream) {
        var self = this;
        stream.on('data', function (chunk) {
            self.push(chunk);
        });
        stream.on('end', function () {
            self.push(null);
        });
        this.readableUnit = stream;
        return this;
    }
82510
function collect(stream, encoding, cb = () => {}) {
  if (typeof encoding === 'function') {
    cb = encoding;
    encoding = null;
  }

  return stream
    .pipe(new Collect({ encoding, objectMode: stream._readableState.objectMode }))
    .collect()
    .then((data) => {
      cb(null, data);
      return data;
    })
    .catch((e) => {
      cb(e);
      throw e;
    });
}
360012
function Stream(i) {
	this.offset = 0;
	if (i instanceof Buffer) {
		this.buffer = i;
	}
	else {
		this.buffer = new Buffer(i || 8192);
	}
}
631948
function appendStream(streams, s) {
    assert.arrayOfObject(streams, 'streams');
    assert.object(s, 'stream');

    if (s instanceof Stream) {
        streams.push({
            raw: false,
            stream: s
        });
    } else {
        assert.optionalBool(s.raw, 'stream.raw');
        assert.object(s.stream, 'stream.stream');
        streams.push(s);
    }
}
265814
function File(data, callback) {
    stream.Duplex.call(this);

    this._header = new Header();
    this._tracks = [];

    if (data && buffer.Buffer.isBuffer(data)) {
        this.setData(data, callback || noop);
    }
}