-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnassh_stream_sftp.js
59 lines (49 loc) · 1.33 KB
/
nassh_stream_sftp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview Stream for passing binary SFTP data through.
*/
/**
* The sftp packet stream.
*
* @param {number} fd
* @param {{client: !nassh.sftp.Client}} info
* @constructor
* @extends {nassh.Stream}
*/
nassh.Stream.Sftp = function(fd, info) {
nassh.Stream.apply(this, [fd]);
this.acknowledgeCount_ = 0;
this.client_ = info.client;
};
nassh.Stream.Sftp.prototype = Object.create(nassh.Stream.prototype);
/** @override */
nassh.Stream.Sftp.constructor = nassh.Stream.Sftp;
/**
* Open the stream asynchronously.
*
* @param {!Object} settings
* @param {function(boolean)} onOpen
* @override
*/
nassh.Stream.Sftp.prototype.asyncOpen = function(settings, onOpen) {
this.acknowledgeCount_ = 0;
setTimeout(() => onOpen(true), 0);
};
/**
* Write to the stream asynchronously.
*
* @param {!ArrayBuffer} data
* @param {function(number)} onSuccess
* @override
*/
nassh.Stream.Sftp.prototype.asyncWrite = function(data, onSuccess) {
if (!this.open) {
throw nassh.Stream.ERR_STREAM_CLOSED;
}
this.acknowledgeCount_ += data.byteLength;
this.client_.writeStreamData(data);
setTimeout(() => onSuccess(this.acknowledgeCount_), 0);
};