{"size": 711, "ext": "js", "max_stars_repo_path": "test/tools/grpc-mock/ServerStreamMock.js", "max_stars_repo_name": "eranor/grpc-promise-meta", "max_stars_repo_stars_event_min_datetime": "2017-05-01T18:35:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T12:24:10.000Z", "max_issues_repo_path": "test/tools/grpc-mock/ServerStreamMock.js", "max_issues_repo_name": "eranor/grpc-promise-meta", "max_issues_repo_issues_event_min_datetime": "2017-06-28T16:30:26.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-29T02:25:22.000Z", "max_forks_repo_path": "test/tools/grpc-mock/ServerStreamMock.js", "max_forks_repo_name": "eranor/grpc-promise-meta", "max_forks_repo_forks_event_min_datetime": "2017-05-21T12:38:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-14T13:15:32.000Z"}
{"max_stars_count": 80, "max_issues_count": 13, "max_forks_count": 18, "avg_line_length": 22.935483871, "max_line_length": 58, "alphanum_fraction": 0.6540084388}
const stream = require('stream');
const util = require('util');

const ServerStreamMock = function (options) {
  if (options == null) {
    options = {};
  }
  stream.Readable.call(this, {objectMode: true});
  this.response = options.response;
};
util.inherits(ServerStreamMock, stream.Readable);

ServerStreamMock.prototype._read = function readBytes () {
  const self = this;
  if (!this.response) {
    this.emit('error', 'some_error');
    return;
  }
  while (this.response.length) {
    const chunk = this.response.shift();
    this.push(chunk);
    if (!this.response.length) {
      this.emit('end');
      return;
    }
  }
  setTimeout(readBytes.bind(self), 1);
};

module.exports = ServerStreamMock;
