{"size": 781, "ext": "js", "max_stars_repo_path": "packages/server/src/storage/ReadableClone.js", "max_stars_repo_name": "ptoussai/dito", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/server/src/storage/ReadableClone.js", "max_issues_repo_name": "ptoussai/dito", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/server/src/storage/ReadableClone.js", "max_forks_repo_name": "ptoussai/dito", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.1081081081, "max_line_length": 72, "alphanum_fraction": 0.5928297055}
import { Readable } from 'stream'

// Based on:
// https://github.com/levansuper/readable-stream-clone
// https://stackoverflow.com/questions/19553837#comment90794237_19561718

export class ReadableClone extends Readable {
  constructor(stream, options) {
    super(options)
    this.stream = stream
    this.events = {
      data: chunk => {
        this.push(chunk)
      },
      end: () => {
        this.push(null)
      },
      error: err => {
        this.emit('error', err)
      }
    }
    for (const [event, callback] of Object.entries(this.events)) {
      this.stream.on(event, callback)
    }
  }

  _destroy() {
    for (const [event, callback] of Object.entries(this.events)) {
      this.stream.off(event, callback)
    }
  }

  _read() {
    // Do nothing
  }
}
