MCPcopy Create free account
hub / github.com/mscdex/ssh2 / WriteStream

Function WriteStream

lib/protocol/SFTP.js:3835–3884  ·  view source on GitHub ↗
(sftp, path, options)

Source from the content-addressed store, hash-verified

3833// TODO: add `concurrency` setting to allow more than one in-flight WRITE
3834// request to server to improve throughput
3835function WriteStream(sftp, path, options) {
3836 if (options === undefined)
3837 options = {};
3838 else if (typeof options === 'string')
3839 options = { encoding: options };
3840 else if (options === null || typeof options !== 'object')
3841 throw new TypeError('"options" argument must be a string or an object');
3842 else
3843 options = Object.create(options);
3844
3845 // For backwards compat do not emit close on destroy.
3846 options.emitClose = false;
3847 options.autoDestroy = false; // Node 14 major change.
3848
3849 WritableStream.call(this, options);
3850
3851 this.path = path;
3852 this.flags = options.flags === undefined ? 'w' : options.flags;
3853 this.mode = options.mode === undefined ? 0o666 : options.mode;
3854
3855 this.start = options.start;
3856 this.autoClose = options.autoClose === undefined ? true : options.autoClose;
3857 this.pos = 0;
3858 this.bytesWritten = 0;
3859 this.isClosed = false;
3860
3861 this.handle = options.handle === undefined ? null : options.handle;
3862 this.sftp = sftp;
3863 this._opening = false;
3864
3865 if (this.start !== undefined) {
3866 checkPosition(this.start, 'start');
3867
3868 this.pos = this.start;
3869 }
3870
3871 if (options.encoding)
3872 this.setDefaultEncoding(options.encoding);
3873
3874 // Node v6.x only
3875 this.on('finish', function() {
3876 if (this._writableState.finalCalled)
3877 return;
3878 if (this.autoClose)
3879 this.destroy();
3880 });
3881
3882 if (!Buffer.isBuffer(this.handle))
3883 this.open();
3884}
3885inherits(WriteStream, WritableStream);
3886
3887WriteStream.prototype._final = function(cb) {

Callers

nothing calls this directly

Calls 3

checkPositionFunction · 0.85
openMethod · 0.80
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…