(sftp, path, options)
| 3633 | } |
| 3634 | |
| 3635 | function ReadStream(sftp, path, options) { |
| 3636 | if (options === undefined) |
| 3637 | options = {}; |
| 3638 | else if (typeof options === 'string') |
| 3639 | options = { encoding: options }; |
| 3640 | else if (options === null || typeof options !== 'object') |
| 3641 | throw new TypeError('"options" argument must be a string or an object'); |
| 3642 | else |
| 3643 | options = Object.create(options); |
| 3644 | |
| 3645 | // A little bit bigger buffer and water marks by default |
| 3646 | if (options.highWaterMark === undefined) |
| 3647 | options.highWaterMark = 64 * 1024; |
| 3648 | |
| 3649 | // For backwards compat do not emit close on destroy. |
| 3650 | options.emitClose = false; |
| 3651 | options.autoDestroy = false; // Node 14 major change. |
| 3652 | |
| 3653 | ReadableStream.call(this, options); |
| 3654 | |
| 3655 | this.path = path; |
| 3656 | this.flags = options.flags === undefined ? 'r' : options.flags; |
| 3657 | this.mode = options.mode === undefined ? 0o666 : options.mode; |
| 3658 | |
| 3659 | this.start = options.start; |
| 3660 | this.end = options.end; |
| 3661 | this.autoClose = options.autoClose === undefined ? true : options.autoClose; |
| 3662 | this.pos = 0; |
| 3663 | this.bytesRead = 0; |
| 3664 | this.isClosed = false; |
| 3665 | |
| 3666 | this.handle = options.handle === undefined ? null : options.handle; |
| 3667 | this.sftp = sftp; |
| 3668 | this._opening = false; |
| 3669 | |
| 3670 | if (this.start !== undefined) { |
| 3671 | checkPosition(this.start, 'start'); |
| 3672 | |
| 3673 | this.pos = this.start; |
| 3674 | } |
| 3675 | |
| 3676 | if (this.end === undefined) { |
| 3677 | this.end = Infinity; |
| 3678 | } else if (this.end !== Infinity) { |
| 3679 | checkPosition(this.end, 'end'); |
| 3680 | |
| 3681 | if (this.start !== undefined && this.start > this.end) { |
| 3682 | throw new ERR_OUT_OF_RANGE( |
| 3683 | 'start', |
| 3684 | `<= "end" (here: ${this.end})`, |
| 3685 | this.start |
| 3686 | ); |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | this.on('end', function() { |
| 3691 | if (this.autoClose) |
| 3692 | this.destroy(); |
nothing calls this directly
no test coverage detected
searching dependent graphs…