UNPKG

5.29 kBJavaScriptView Raw
1// This wrapper class is used to retain backwards compatibility with
2// pre-v0.4 ssh2. If it weren't for `read()` and `write()` being used by the
3// streams2/3 API, we could just pass the SFTPStream directly to the end user...
4
5var inherits = require('util').inherits;
6var EventEmitter = require('events').EventEmitter;
7
8function SFTPWrapper(stream) {
9 var self = this;
10
11 EventEmitter.call(this);
12
13 this._stream = stream;
14
15 stream.on('error', function(err) {
16 self.emit('error', err);
17 }).on('end', function() {
18 self.emit('end');
19 }).on('close', function() {
20 self.emit('close');
21 }).on('continue', function() {
22 self.emit('continue');
23 });
24}
25inherits(SFTPWrapper, EventEmitter);
26
27// stream-related methods to pass on
28SFTPWrapper.prototype.end = function() {
29 return this._stream.end();
30};
31// SFTPStream client methods
32SFTPWrapper.prototype.createReadStream = function(path, options) {
33 return this._stream.createReadStream(path, options);
34};
35SFTPWrapper.prototype.createWriteStream = function(path, options) {
36 return this._stream.createWriteStream(path, options);
37};
38SFTPWrapper.prototype.open = function(path, flags, attrs, cb) {
39 return this._stream.open(path, flags, attrs, cb);
40};
41SFTPWrapper.prototype.close = function(handle, cb) {
42 return this._stream.close(handle, cb);
43};
44SFTPWrapper.prototype.read = function(handle, buf, off, len, position, cb) {
45 return this._stream.readData(handle, buf, off, len, position, cb);
46};
47SFTPWrapper.prototype.write = function(handle, buf, off, len, position, cb) {
48 return this._stream.writeData(handle, buf, off, len, position, cb);
49};
50SFTPWrapper.prototype.fastGet = function(remotePath, localPath, opts, cb) {
51 return this._stream.fastGet(remotePath, localPath, opts, cb);
52};
53SFTPWrapper.prototype.fastPut = function(localPath, remotePath, opts, cb) {
54 return this._stream.fastPut(localPath, remotePath, opts, cb);
55};
56SFTPWrapper.prototype.readFile = function(path, options, callback_) {
57 return this._stream.readFile(path, options, callback_);
58};
59SFTPWrapper.prototype.writeFile = function(path, data, options, callback_) {
60 return this._stream.writeFile(path, data, options, callback_);
61};
62SFTPWrapper.prototype.appendFile = function(path, data, options, callback_) {
63 return this._stream.appendFile(path, data, options, callback_);
64};
65SFTPWrapper.prototype.exists = function(path, cb) {
66 return this._stream.exists(path, cb);
67};
68SFTPWrapper.prototype.unlink = function(filename, cb) {
69 return this._stream.unlink(filename, cb);
70};
71SFTPWrapper.prototype.rename = function(oldPath, newPath, cb) {
72 return this._stream.rename(oldPath, newPath, cb);
73};
74SFTPWrapper.prototype.mkdir = function(path, attrs, cb) {
75 return this._stream.mkdir(path, attrs, cb);
76};
77SFTPWrapper.prototype.rmdir = function(path, cb) {
78 return this._stream.rmdir(path, cb);
79};
80SFTPWrapper.prototype.readdir = function(where, opts, cb) {
81 return this._stream.readdir(where, opts, cb);
82};
83SFTPWrapper.prototype.fstat = function(handle, cb) {
84 return this._stream.fstat(handle, cb);
85};
86SFTPWrapper.prototype.stat = function(path, cb) {
87 return this._stream.stat(path, cb);
88};
89SFTPWrapper.prototype.lstat = function(path, cb) {
90 return this._stream.lstat(path, cb);
91};
92SFTPWrapper.prototype.opendir = function(path, cb) {
93 return this._stream.opendir(path, cb);
94};
95SFTPWrapper.prototype.setstat = function(path, attrs, cb) {
96 return this._stream.setstat(path, attrs, cb);
97};
98SFTPWrapper.prototype.fsetstat = function(handle, attrs, cb) {
99 return this._stream.fsetstat(handle, attrs, cb);
100};
101SFTPWrapper.prototype.futimes = function(handle, atime, mtime, cb) {
102 return this._stream.futimes(handle, atime, mtime, cb);
103};
104SFTPWrapper.prototype.utimes = function(path, atime, mtime, cb) {
105 return this._stream.utimes(path, atime, mtime, cb);
106};
107SFTPWrapper.prototype.fchown = function(handle, uid, gid, cb) {
108 return this._stream.fchown(handle, uid, gid, cb);
109};
110SFTPWrapper.prototype.chown = function(path, uid, gid, cb) {
111 return this._stream.chown(path, uid, gid, cb);
112};
113SFTPWrapper.prototype.fchmod = function(handle, mode, cb) {
114 return this._stream.fchmod(handle, mode, cb);
115};
116SFTPWrapper.prototype.chmod = function(path, mode, cb) {
117 return this._stream.chmod(path, mode, cb);
118};
119SFTPWrapper.prototype.readlink = function(path, cb) {
120 return this._stream.readlink(path, cb);
121};
122SFTPWrapper.prototype.symlink = function(targetPath, linkPath, cb) {
123 return this._stream.symlink(targetPath, linkPath, cb);
124};
125SFTPWrapper.prototype.realpath = function(path, cb) {
126 return this._stream.realpath(path, cb);
127};
128// extended requests
129SFTPWrapper.prototype.ext_openssh_rename = function(oldPath, newPath, cb) {
130 return this._stream.ext_openssh_rename(oldPath, newPath, cb);
131};
132SFTPWrapper.prototype.ext_openssh_statvfs = function(path, cb) {
133 return this._stream.ext_openssh_statvfs(path, cb);
134};
135SFTPWrapper.prototype.ext_openssh_fstatvfs = function(handle, cb) {
136 return this._stream.ext_openssh_fstatvfs(handle, cb);
137};
138SFTPWrapper.prototype.ext_openssh_hardlink = function(oldPath, newPath, cb) {
139 return this._stream.ext_openssh_hardlink(oldPath, newPath, cb);
140};
141SFTPWrapper.prototype.ext_openssh_fsync = function(handle, cb) {
142 return this._stream.ext_openssh_fsync(handle, cb);
143};
144
145module.exports = SFTPWrapper;