This constructor will create a I/O line stream
from a writable and readable stream
553723
function LineStream(writeStream, readStream) {
    var self = this;
    this.writeStream = writeStream;
    this.readStream = readStream;

    // resume streams
    this.readStream.resume();

    // save data in this buffer
    this.buffer = "";

    // new data from stream will be handled by this
    this.readStream.on('data', function (chunk) {
      self.buffer += chunk;

      // go through the buffer and isolate each message by a linebreak
      var i, start = 0;
      while ((i = self.buffer.indexOf('\n', start)) >= 0) {

        // parse line as JSON and emit line
        self.emit('message', JSON.parse(self.buffer.slice(start, i)));
        start = i + 1;
      }
      self.buffer = self.buffer.slice(start);
    });
  }
18067
function(src, dest){
      self.logger.info('generating '+dest); 
      fs.createReadStream(src).pipe(fs.createWriteStream(dest)); 
    }
69706
protected InterleavedInputStream createInterleavedInputStream(InputStream in,
      int metaDataBlockLength, int dataBlockLength,
      SimpleSeekableFormat.MetaDataConsumer consumer) {
    return new InterleavedInputStream(in, metaDataBlockLength, dataBlockLength, consumer);
  }
286227
private static ByteArrayOutputStream sizeLine(final InputStream stream)
        throws IOException {
        State state = State.NORMAL;
        final ByteArrayOutputStream result = new ByteArrayOutputStream();
        while (state != State.END) {
            state = next(stream, state, result);
        }
        return result;
    }
177048
public Object fromStream(final byte[] iStream) throws IOException {
		if (iStream == null || iStream.length == 0)
			// NULL VALUE
			return null;

		final ORecordInternal<?> obj = Orient.instance().getRecordFactoryManager().newInstance();

		final ORID rid = new ORecordId().fromStream(iStream);

		obj.setIdentity(rid.getClusterId(), rid.getClusterPosition());
		return obj;
	}
990524
public Object fromStream(final byte[] iStream) throws IOException {
		if (iStream == null || iStream.length == 0)
			// NULL VALUE
			return null;

		final int classNameSize = OBinaryProtocol.bytes2int(iStream);
		if (classNameSize <= 0)
			OLogManager.instance().error(this, "Class signature not found in ANY element: " + Arrays.toString(iStream),
					OSerializationException.class);

		final String className = OBinaryProtocol.bytes2string(iStream, 4, classNameSize);

		try {
			final OSerializableStream stream;
			// CHECK FOR ALIASES
			if (className.equalsIgnoreCase("q"))
				// QUERY
				stream = new OSQLSynchQuery<Object>();
			else if (className.equalsIgnoreCase("c"))
				// SQL COMMAND
				stream = new OCommandSQL();
			else if (className.equalsIgnoreCase("s"))
				// SCRIPT COMMAND
				stream = new OCommandScript();
			else
				// CREATE THE OBJECT BY INVOKING THE EMPTY CONSTRUCTOR
				stream = (OSerializableStream) Class.forName(className).newInstance();

			return stream.fromStream(OArrays.copyOfRange(iStream, 4 + classNameSize, iStream.length));

		} catch (Exception e) {
			OLogManager.instance().error(this, "Error on unmarshalling content. Class: " + className, e, OSerializationException.class);
		}
		return null;
	}
418033
def from_blob(cls, blob):
        
        stream = BytesIO(blob)
        return cls._from_stream(stream, blob)
92418
def new_encoded_stream(args, stream):
    ''''''
    if args.ascii_print:
        return wpull.util.ASCIIStreamWriter(stream)
    else:
        return stream
1262664
function ReadableStream(options, cursor) {
  if (cursor) this._cursor = cursor;
  this._pending = 0; // How many time we called _read while no cursor was available
  this._index = 0;
  this._maxRecursion = 1000; // Hardcoded
  this._highWaterMark = options.highWaterMark;
  this._closed = false;

  Readable.call(this, {
    objectMode: true,
    highWaterMark: this._highWaterMark
  });
}
1212194
public StringBuilder toStream(final StringBuilder iOutput, Object iValue) {
    if (iValue != null) {
      if (!(iValue instanceof OSerializableStream))
        throw new OSerializationException("Cannot serialize the object since it's not implements the OSerializableStream interface");

      OSerializableStream stream = (OSerializableStream) iValue;
      iOutput.append(iValue.getClass().getName());
      iOutput.append(OStreamSerializerHelper.SEPARATOR);
      iOutput.append(OBase64Utils.encodeBytes(stream.toStream()));
    }
    return iOutput;
  }
1108725
private <T extends StreamWithTimeout> T createStream(
			final SupplierWithException<T, IOException> streamOpener,
			final HashSet<T> openStreams,
			final boolean output) throws IOException {

		final int outputLimit = output && maxNumOpenOutputStreams > 0 ? maxNumOpenOutputStreams : Integer.MAX_VALUE;
		final int inputLimit = !output && maxNumOpenInputStreams > 0 ? maxNumOpenInputStreams : Integer.MAX_VALUE;
		final int totalLimit = maxNumOpenStreamsTotal > 0 ? maxNumOpenStreamsTotal : Integer.MAX_VALUE;
		final int outputCredit = output ? 1 : 0;
		final int inputCredit = output ? 0 : 1;

		// because waiting for availability may take long, we need to be interruptible here
		// and handle interrupted exceptions as I/O errors
		// even though the code is written to make sure the lock is held for a short time only,
		// making the lock acquisition interruptible helps to guard against the cases where
		// a supposedly fast operation (like 'getPos()' on a stream) actually takes long.
		try {
			lock.lockInterruptibly();
			try {
				// some integrity checks
				assert openOutputStreams.size() <= numReservedOutputStreams;
				assert openInputStreams.size() <= numReservedInputStreams;

				// wait until there are few enough streams so we can open another
				waitForAvailability(totalLimit, outputLimit, inputLimit);

				// We do not open the stream here in the locked scope because opening a stream
				// could take a while. Holding the lock during that operation would block all concurrent
				// attempts to try and open a stream, effectively serializing all calls to open the streams.
				numReservedOutputStreams += outputCredit;
				numReservedInputStreams += inputCredit;
			}
			finally {
				lock.unlock();
			}
		}
		catch (InterruptedException e) {
			// restore interruption flag
			Thread.currentThread().interrupt();
			throw new IOException("interrupted before opening stream");
		}

		// open the stream outside the lock.
		boolean success = false;
		try {
			final T out = streamOpener.get();

			// add the stream to the set, need to re-acquire the lock
			lock.lock();
			try {
				openStreams.add(out);
			} finally {
				lock.unlock();
			}

			// good, can now return cleanly
			success = true;
			return out;
		}
		finally {
			if (!success) {
				// remove the reserved credit
				// we must open this non-interruptibly, because this must succeed!
				lock.lock();
				try {
					numReservedOutputStreams -= outputCredit;
					numReservedInputStreams -= inputCredit;
					available.signalAll();
				} finally {
					lock.unlock();
				}
			}
		}
	}
1069511
def line_iterator(readable_file, size=None):
    # type: (IO[bytes], Optional[int]) -> Iterator[bytes]
    
    read = readable_file.read
    line = []
    byte = b"1"
    if size is None or size < 0:
        while byte:
            byte = read(1)
            line.append(byte)
            if byte in b"\n":
                yield b"".join(line)
                del line[:]

    else:
        while byte and size:
            byte = read(1)
            size -= len(byte)
            line.append(byte)
            if byte in b"\n" or not size:
                yield b"".join(line)
                del line[:]
127691
private void init() throws IOException {
        if (initialized.compareAndSet(false, true)) {
            log.debug("Init: {}", mode);
            // if the path is null, the consumer has been uninitialized
            if (path != null) {
                if (log.isDebugEnabled()) {
                    Path parent = path.getParent();
                    log.debug("Parent abs: {} dir: {}", parent.isAbsolute(), Files.isDirectory(parent));
                }
                if (IClientStream.MODE_APPEND.equals(mode)) {
                    if (Files.notExists(path)) {
                        throw new IOException("File to be appended doesnt exist, verify the record mode");
                    }
                    log.debug("Path: {}\nRead: {} write: {} size: {}", path, Files.isReadable(path), Files.isWritable(path), Files.size(path));
                    writer = new FLVWriter(path, true);
                } else if (IClientStream.MODE_RECORD.equals(mode)) {
                    try {
                        // delete existing file
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                        // ensure parent dirs exist
                        Files.createDirectories(path.getParent());
                        // create the file
                        path = Files.createFile(path);
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                    if (!Files.isWritable(path)) {
                        throw new IOException("File is not writable");
                    }
                    log.debug("Path: {}\nRead: {} write: {}", path, Files.isReadable(path), Files.isWritable(path));
                    writer = new FLVWriter(path, false);
                } else {
                    try {
                        // delete existing file since we're not recording nor appending
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                }
            } else {
                log.warn("Consumer is uninitialized");
            }
            log.debug("Init - complete");
        }
    }
1229381
function getStreamStream (readable, file) {
  return () => {
    const counter = new stream.Transform()
    counter._transform = function (buf, enc, done) {
      file.length += buf.length
      this.push(buf)
      done()
    }
    readable.pipe(counter)
    return counter
  }
}
1254060
private void init() throws IOException {
        if (initialized.compareAndSet(false, true)) {
            log.debug("Init: {}", mode);
            // instance an executor for queue handling
            scheduledExecutorService = Executors.newScheduledThreadPool(schedulerThreadSize, new CustomizableThreadFactory("FileConsumerExecutor-"));
            // if the path is null, the consumer has been uninitialized
            if (path != null) {
                if (log.isDebugEnabled()) {
                    Path parent = path.getParent();
                    log.debug("Parent abs: {} dir: {}", parent.isAbsolute(), Files.isDirectory(parent));
                }
                if (IClientStream.MODE_APPEND.equals(mode)) {
                    if (Files.notExists(path)) {
                        throw new IOException("File to be appended doesnt exist, verify the record mode");
                    }
                    log.debug("Path: {}\nRead: {} write: {} size: {}", path, Files.isReadable(path), Files.isWritable(path), Files.size(path));
                    writer = new FLVWriter(path, true);
                } else if (IClientStream.MODE_RECORD.equals(mode)) {
                    try {
                        // delete existing file
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                        // ensure parent dirs exist
                        Files.createDirectories(path.getParent());
                        // create the file
                        path = Files.createFile(path);
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                    if (!Files.isWritable(path)) {
                        throw new IOException("File is not writable");
                    }
                    log.debug("Path: {}\nRead: {} write: {}", path, Files.isReadable(path), Files.isWritable(path));
                    writer = new FLVWriter(path, false);
                    if (audioConfigurationTag != null) {
                        writer.writeTag(audioConfigurationTag);
                    }
                    if (videoConfigurationTag != null) {
                        writer.writeTag(videoConfigurationTag);
                        gotVideoKeyframe = true;
                    }
                } else {
                    //throw new IllegalStateException(String.format("Illegal mode type: %s", mode));
                    try {
                        // delete existing file since we're not recording nor appending
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                }
            } else {
                log.warn("Consumer is uninitialized");
            }
            log.debug("Init - complete");
        }
    }
798502
async function createBlobReadStream(dir, oid) {
  const { object: content } = await git.readObject({ dir, oid });
  const stream = new PassThrough();
  stream.end(content);
  return stream;
}
955400
function createWritable() {
    var $args = arguments;return new Promise(function ($return, $error) {
        var file, ws;
        file = $args.length > 0 && $args[0] !== undefined ? $args[0] : getTempFile();
        return Promise.resolve(openFileForWrite(file)).then(function ($await_2) {
            try {
                ws = $await_2;
                return $return(ws);
            } catch ($boundEx) {
                return $error($boundEx);
            }
        }.bind(this), $error);
    }.bind(this));
}