Reads the given stream and returns it as string.
Rejects if data is larger than MAX_TEXT_LENGTH.

@param {stream.Readable} stream
@returns {Promise<string>} received text
356419
function streamToText(stream) {
    return new Promise((fulfill, reject) => {
        let chunks = [];
        let length = 0;
        stream.setEncoding('utf8');
        stream.on('data', chunk => {
            length += chunk.length;
            if (length > MAX_TEXT_LENGTH) {
                reject(new Error('Response is too big'));
                return;
            }
            chunks.push(chunk);
        });
        stream.on('end', () => {
            fulfill(chunks.join(''));
        });
        stream.on('error', err => {
            reject(err);
        });
    });
}
182593
async function convertStream(data, streaming) {
  if (!streaming && util.isStream(data)) {
    return stream.readToEnd(data);
  }
  if (streaming && !util.isStream(data)) {
    data = new ReadableStream({
      start(controller) {
        controller.enqueue(data);
        controller.close();
      }
    });
  }
  if (streaming === 'node') {
    data = stream.webToNode(data);
  }
  return data;
}
1011752
function readIntoBuf(stream) {
  return new Promise((resolve, reject) => {
    const chunks = []

    stream.on('data', chunk => {
      chunks.push(chunk)
    })

    stream.on('error', err => {
      reject(err)
    })

    stream.on('end', () => {
      resolve(Buffer.concat(chunks))
    })
  })
}
797152
function tryRead(fd, buff, offset, length) {
  return new Promise((resolve, reject) => {
    fs.read(fd, buff, offset, length, null, (err, bytesRead, buffer) => {
      if (err) return reject(err);
      const buffLen = buffer.length;
      offset += bytesRead;
      if (offset >= buffLen) return resolve(buff);
      if ((offset + length) >= buffLen) length = buffLen - offset;
      return resolve();
    });
  })
  .then(
    (fullBuffer) => {
      return fullBuffer ? { data: fullBuffer, fd: fd }
                        : tryRead(fd, buff, offset, length);
    },
    (err) => { throw err; }
  );
}
1026097
function checkUntil(resultWithData, data, ended) {
      let desiredLength;
      try {
        desiredLength = until(resultWithData, data, ended);
      } catch (errUntil) {
        doReject(errUntil, true);
        return true;
      }

      const resultLength = result ? result.length : 0;
      if (typeof desiredLength === 'number') {
        if (desiredLength > resultLength) {
          debug(
            'until returned a desired length of %d.  '
              + 'Only have %d.  Reading up to %d.',
            desiredLength, resultLength, desiredLength
          );
          numSize = desiredLength;
          size = desiredLength - resultLength;
        } else if (desiredLength >= 0) {
          debug(
            'until returned a desired length of %d out of %d',
            desiredLength, resultLength
          );
          if (desiredLength < resultLength) {
            if (ended) {
              debug('Unable to unshift:  Can not unshift after end.');
            } else {
              result = tryUnshift(stream, result, desiredLength, true);
            }
          }
          doResolve();
          return true;
        } else {
          debug('until returned %d, continuing to read', desiredLength);
        }
      } else if (desiredLength === true) {
        debug('until returned true, read finished.');
        doResolve();
        return true;
      } else if (desiredLength !== undefined
          && desiredLength !== null
          && desiredLength !== false) {
        // Note:  Although this could be allowed, it causes an Error so that
        // future versions may add behavior for these values without causing
        // breakage.
        doReject(
          new TypeError(
            `non-numeric, non-boolean until() result: ${desiredLength}`
          ),
          true
        );
      } else {
        debug('until returned %s, continuing to read', desiredLength);
      }

      return false;
    }
912997
function readValue(str) {
            shared.utils.dassert(shared.utils.isValue(str));
            var rs = new ReadStream(str);
            return rs.readNextValue();
        }
1061494
function LineReader(file) {
  if (typeof file === 'string') {
    this.readstream = fs.createReadStream(file);
  } else {
    this.readstream = file;
  }
  this.remainBuffers = [];
  var self = this;
  this.readstream.on('data', function (data) {
    self.ondata(data);
  });
  this.readstream.on('error', function (err) {
    self.emit('error', err);
  });
  this.readstream.on('end', function () {
    self.emit('end');
  });
}
1055741
function handleText(stream, mdState) {
    var match;
    if (stream.match(/^\w+:\/\/\S+/)) {
      return 'linkhref';
    }
    if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) {
      return mdMode.getType(mdState);
    }
    if (match = stream.match(/^[^\[*\\<>` ]+/)) {
      var word = match[0];
      if (word[0] === '_' && word[word.length-1] === '_') {
        stream.backUp(word.length);
        return undefined;
      }
      return mdMode.getType(mdState);
    }
    if (stream.eatSpace()) {
      return null;
    }
  }
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
}
592794
function readPNG(file) {
    const deferred = Q.defer();
    const onerror = deferred.reject.bind(deferred);
    const stream = fs.createReadStream(file);
    stream.on("error", onerror);
    pngparse.parseStream(stream, function(err, image) {
        if (err) {
            console.log("Failed to load " + file);
            onerror(err);
            return;
        }
        deferred.resolve(image);
    });
    return deferred.promise;
}
989564
def read(stream):
        '''
        

        '''
        (must_close, stream) = _open_stream(stream, 'read')
        try:
            data = PlyData._parse_header(stream)
            for elt in data:
                elt._read(stream, data.text, data.byte_order)
        finally:
            if must_close:
                stream.close()

        return data
793360
function promisify_read_stream() {
    var transformer = function (stream_promise) {
        var res = new PStream();
        res.to = function (dest) {
            when(stream_promise, function (stream) {
                PStream.wrap_read_stream(stream).to(dest);
            }, function (err) {
                dest.error(err);
            });
        };
        return res.sanitize();
    };

    transformer.for_property = function (obj_promise, prop) {
        return transformer(when(obj_promise, function (obj) {
            return obj[prop];
        }));
    };

    return transformer;
}
110
function readFile(path, fileName) {
  return new Promise((resolve, reject) => {
    fs.readFile(`${path}/${fileName}`, 'utf8', (err, content) => {
      if (err) {
        return reject(err)
      }

      return resolve(content)
    })
  })
}
1285377
private static String inputStreamToString(InputStream stream)
			throws IOException {
		ByteArrayOutputStream result = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int length;
		String resultString = null;
		while ((length = stream.read(buffer)) != -1) {
			result.write(buffer, 0, length);
		}
		resultString = result.toString("UTF-8");
		return resultString;
	}
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);
        });
    });
}
815590
function getInputAsStream(input) {

    return new Promise(function(resolve, reject) {

        if (input.write) {

            // already a stream
            resolve(input);
        }
        else {

            // read from file
            fs.readFileAsync(input, 'utf-8').then(function(data) {

                // convert file string into stream and pipe into jsdoc-parse
                var stream = string2stream(data);

                // return stream
                resolve(stream);

            })
            .catch(function(err) {
                reject(err);
            });
        }

    });
}
251530
function streamToPromise(stream) {
    return new Promise((resolve, reject) => {
        stream.on('error', reject);
        stream.on('end', resolve);
    });
}