-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
404 lines (404 loc) · 10.6 KB
/
index.d.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/// <reference types="node" />
import * as Events from 'events';
import * as Net from 'net';
/**
* The default (string) encoding.
*/
export declare const DEFAULT_ENCODING: string;
/**
* Default value that indicates if compression should be used or not.
*/
export declare let Compress: boolean;
/**
* Default working directory.
*/
export declare let DefaultCWD: string;
/**
* The default text encoding.
*/
export declare let DefaultEncoding: string;
/**
* Default data transformer.
*/
export declare let DefaultDataTransformer: DataTransformer;
/**
* Default handshake transformer.
*/
export declare let DefaultHandshakeTransformer: DataTransformer;
/**
* The default size for a maximum data package.
*/
export declare let DefaultMaxPackageSize: number;
/**
* The default password generator.
*/
export declare let DefaultPasswordGenerator: PasswordGenerator;
/**
* Default buffer size for reading streams.
*/
export declare let DefaultReadBufferSize: number;
/**
* The default RSA key size.
*/
export declare let DefaultRSAKeySize: number;
/**
* A compression result.
*/
export interface CompressionResult {
/**
* The compressed data (if available).
*/
compressed?: Buffer;
/**
* The suggested data to use.
*/
data: Buffer;
/**
* The error (if occurred).
*/
error?: any;
/**
* Data is compressed or not.
*/
isCompressed: boolean;
/**
* The original (uncompressed) data.
*/
uncompressed: Buffer;
}
/**
* A data transformer.
*
* @param {DataTransformerContext} ctx The context.
*
* @return {DataTransformerResult} The result.
*/
export declare type DataTransformer = (ctx: DataTransformerContext) => DataTransformerResult;
/**
* A context for a data transformer.
*/
export interface DataTransformerContext {
/**
* The (source) data.
*/
readonly data: Buffer;
/**
* The direction.
*/
readonly direction: DataTransformerDirection;
}
/**
* List of data transform directions.
*/
export declare enum DataTransformerDirection {
/**
* Transform UNtransformed data.
*/
Transform = 1,
/**
* Restore transformed data.
*/
Restore = 2,
}
/**
* A result for of a data transformer.
*/
export declare type DataTransformerResult = Buffer | PromiseLike<Buffer>;
/**
* A listener callback.
*
* @param {any} err The error (if occurred).
* @param {SimpleSocket} [socket] The socket if no error ocurred.
*/
export declare type ListenCallback = (err: any, socket?: SimpleSocket) => void;
/**
* A password generator.
*
* @return {PasswordGeneratorResult} The result.
*/
export declare type PasswordGenerator = () => PasswordGeneratorResult;
/**
* The result of a password generator.
*/
export declare type PasswordGeneratorResult = Buffer | PromiseLike<Buffer> | string | PromiseLike<string>;
/**
* List of socket types.
*/
export declare enum SocketType {
/**
* Server
*/
Server = 1,
/**
* Client
*/
Client = 2,
}
/**
* A "simple" socket.
*/
export declare class SimpleSocket extends Events.EventEmitter {
/**
* Stores the wrapped socket.
*/
protected _socket: Net.Socket;
/**
* Stores the type.
*/
protected _type: SocketType;
/**
* Initializes a new instance of that class.
*
* @param {Socket} type The type.
* @param {Net.Socket} [socket] The "real" socket.
*/
constructor(type: SocketType, socket?: Net.Socket);
/**
* Gets the symetric encryption algorithm.
*/
readonly algorithm: string;
/**
* Try compress data or not.
*/
compress: boolean;
/**
* The path of the working directory.
*/
cwd: string;
/**
* A custom function that transformes data
* before it is send or after it has been received.
*/
dataTransformer: DataTransformer;
/**
* Disposes the socket.
*/
dispose(): void;
/**
* Gets or sets the (string) encoding to use.
*/
encoding: string;
/**
* Sends the connection.
*
* @param {any} [data] The optional data to send.
* @param {string} [encoding] The encoding to use.
*
* @return {Promise<any>} The promise.
*/
end(data?: any, encoding?: string): Promise<any>;
/**
* Generates a password based on the 'passwordGenerator' property.
*
* @param {Promise<Buffer>} The promise.
*/
protected generatePassword(): Promise<Buffer>;
/**
* Returns the working directory.
*
* @return {string} The working directory.
*/
protected getCwd(): string;
/**
* Returns the (string) encoding that should be used by that socket.
*
* @return {string} The encoding.
*/
protected getEncoding(): string;
/**
* Gets the maximum size for a package.
*
* @return {number} The maximum package size.
*/
getMaxPackageSize(): number;
/**
* Gets the size for a RSA key.
*
* @return {number} The RSA key size.
*/
protected getRSAKeySize(): number;
/**
* Returns the buffer size for reading streams.
*
* @return {number} The buffer size.
*/
protected getReadBufferSize(): number;
/**
* A custom function that transforms the handshake
* public key before it is send or after it has been received.
*/
handshakeTransformer: DataTransformer;
/**
* Makes a CLIENT handshake.
*
* @param {Promise<Buffer>} The promise.
*/
protected makeClientHandshake(): Promise<Buffer>;
/**
* Makes a handshake if needed.
*
* @param {Promise<Buffer>} The promise.
*/
makeHandshakeIfNeeded(): Promise<Buffer>;
/**
* Makes a SERVER handshake.
*
* @param {Promise<Buffer>} The promise.
*/
protected makeServerHandshake(): Promise<Buffer>;
/**
* Defines the maximum size of a package.
*/
maxPackageSize: number;
/**
* Stores the current password.
*/
password: Buffer;
/**
* Defines a custom logic to generate a password (for the connection).
*/
passwordGenerator: PasswordGenerator;
/**
* Reads data from the remote.
*
* @param {Promise<Buffer>} The promise.
*/
read(): Promise<Buffer>;
/**
* The default buffer size for reading a stream.
*/
readBufferSize: number;
/**
* Reads data from remote and writes it to a file on this machine.
*
* @param {string} path The path to the target file.
* @param {string|number} [flags] The custom flags for opening the target file.
*
* @return {Promise<number>} The promise.
*/
readFile(path: string, flags?: string | number): Promise<number>;
/**
* Reads data as JSON object.
*
* @return {Promise<T>} The promise.
*/
readJSON<T>(): Promise<T>;
/**
* Reads data from remote and writes it to a stream on this machine.
*
* @param {number} fdTarget The stream pointer of the target.
*
* @return {Promise<number>} The promise.
*/
readStream(fdTarget: number): Promise<number>;
/**
* Reads data as string.
*
* @return {Promise<string>} The promise.
*/
readString(): Promise<string>;
/**
* The RSA key size.
*/
rsaKeySize: number;
/**
* Sets up the events.
*/
protected setupEvents(): void;
/**
* Gets the wrapped socket.
*
* @return {Net.Socket} The wrapped socket.
*/
readonly socket: Net.Socket;
/**
* Gets the socket type.
*/
readonly type: SocketType;
/**
* Tries to compress data.
*
* @param {any} data The data to compress.
*
* @return {Promise<CompressionResult>} The promise.
*/
protected tryCompress(data: any): Promise<CompressionResult>;
/**
* Reads data from the remote.
*
* @param {Promise<Buffer>} The promise.
*/
write(data: any): Promise<Buffer>;
/**
* Sends the data of a file to the remote.
*
* @param {string} path The path of the file to send.
* @param {number} [maxSize] The maximum number of bytes to send.
* @param {number} [bufferSize] The custom buffer size for the read operation(s).
* @param {string|number} [flags] The custom flags for opening the file.
*
* @return {Promise<number>} The promise.
*/
writeFile(path: string, maxSize?: number, bufferSize?: number, flags?: string | number): Promise<number>;
/**
* Sends an object / value as JSON string.
*
* @param {T} obj The object to send.
*
* @returns {Promise<Buffer>} The promise.
*/
writeJSON<T>(obj: T): Promise<Buffer>;
/**
* Sends the data of a stream to the remote.
*
* @param {number} fdSrc The stream pointer from where to read.
* @param {number} [maxSize] The maximum number of bytes to send.
* @param {number} [bufferSize] The custom buffer size for the read operation(s).
*
* @return {Promise<number>} The promise.
*/
writeStream(fdSrc: number, maxSize?: number, bufferSize?: number): Promise<number>;
}
/**
* Connects to a remote (server).
*
* @param {number} port The TCP port of the remote machine.
* @param {string} host The host (address).
*
* @return {Promise<SimpleSocket>} The promise.
*/
export declare function connect(port: number, host?: string): Promise<SimpleSocket>;
/**
* Creates a new instance.
*
* @param {Net.Socket} [socket] The "real" socket.
* @param {SocketType} [type] The type.
*
* @return {SimpleSocket} The new instance.
*/
export declare function create(socket?: Net.Socket, type?: SocketType): SimpleSocket;
/**
* Creates a new CLIENT instance.
*
* @param {Net.Socket} [socket] The "real" socket.
*
* @return {SimpleSocket} The new instance.
*/
export declare function createClient(socket?: Net.Socket): SimpleSocket;
/**
* Creates a new SERVER instance.
*
* @param {Net.Socket} [socket] The "real" socket.
*
* @return {SimpleSocket} The new instance.
*/
export declare function createServer(socket?: Net.Socket): SimpleSocket;
/**
* Starts listening on a port.
*
* @param {number} port The TCP port to listen on.
* @param {ListenCallback} cb The listener callback.
*
* @return {Promise<Net.Server>} The promise.
*/
export declare function listen(port: number, cb: ListenCallback): Promise<Net.Server>;