trzsz2 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.cn.md +64 -0
- package/README.md +70 -0
- package/dist/browser/buffer.d.ts +76 -0
- package/dist/browser/comm.d.ts +162 -0
- package/dist/browser/escape.d.ts +33 -0
- package/dist/browser/index.d.ts +17 -0
- package/dist/browser/options.d.ts +57 -0
- package/dist/browser/progress.d.ts +100 -0
- package/dist/browser/transfer.d.ts +259 -0
- package/dist/browser/trzsz2.js +6147 -0
- package/dist/browser/trzsz2.js.map +1 -0
- package/dist/browser/trzsz2.min.js +19 -0
- package/dist/buffer.d.ts +76 -0
- package/dist/cjs/buffer.cjs +252 -0
- package/dist/cjs/buffer.cjs.map +1 -0
- package/dist/cjs/buffer.d.ts +76 -0
- package/dist/cjs/comm.cjs +292 -0
- package/dist/cjs/comm.cjs.map +1 -0
- package/dist/cjs/comm.d.ts +162 -0
- package/dist/cjs/escape.cjs +86 -0
- package/dist/cjs/escape.cjs.map +1 -0
- package/dist/cjs/escape.d.ts +33 -0
- package/dist/cjs/index.cjs +30 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/cjs/node_modules/pako/dist/pako.esm.cjs +4177 -0
- package/dist/cjs/node_modules/pako/dist/pako.esm.cjs.map +1 -0
- package/dist/cjs/node_modules/ts-md5/dist/esm/md5.cjs +353 -0
- package/dist/cjs/node_modules/ts-md5/dist/esm/md5.cjs.map +1 -0
- package/dist/cjs/options.d.ts +57 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/progress.cjs +313 -0
- package/dist/cjs/progress.cjs.map +1 -0
- package/dist/cjs/progress.d.ts +100 -0
- package/dist/cjs/transfer.cjs +706 -0
- package/dist/cjs/transfer.cjs.map +1 -0
- package/dist/cjs/transfer.d.ts +259 -0
- package/dist/cjs-full/buffer.d.ts +76 -0
- package/dist/cjs-full/comm.d.ts +162 -0
- package/dist/cjs-full/escape.d.ts +33 -0
- package/dist/cjs-full/index.cjs +6144 -0
- package/dist/cjs-full/index.cjs.map +1 -0
- package/dist/cjs-full/index.d.ts +17 -0
- package/dist/cjs-full/options.d.ts +57 -0
- package/dist/cjs-full/package.json +3 -0
- package/dist/cjs-full/progress.d.ts +100 -0
- package/dist/cjs-full/transfer.d.ts +259 -0
- package/dist/comm.d.ts +162 -0
- package/dist/escape.d.ts +33 -0
- package/dist/esm/buffer.d.ts +76 -0
- package/dist/esm/buffer.js +252 -0
- package/dist/esm/buffer.js.map +1 -0
- package/dist/esm/comm.d.ts +162 -0
- package/dist/esm/comm.js +292 -0
- package/dist/esm/comm.js.map +1 -0
- package/dist/esm/escape.d.ts +33 -0
- package/dist/esm/escape.js +86 -0
- package/dist/esm/escape.js.map +1 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/node_modules/pako/dist/pako.esm.js +4177 -0
- package/dist/esm/node_modules/pako/dist/pako.esm.js.map +1 -0
- package/dist/esm/node_modules/ts-md5/dist/esm/md5.js +353 -0
- package/dist/esm/node_modules/ts-md5/dist/esm/md5.js.map +1 -0
- package/dist/esm/options.d.ts +57 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/progress.d.ts +100 -0
- package/dist/esm/progress.js +313 -0
- package/dist/esm/progress.js.map +1 -0
- package/dist/esm/transfer.d.ts +259 -0
- package/dist/esm/transfer.js +706 -0
- package/dist/esm/transfer.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/options.d.ts +57 -0
- package/dist/progress.d.ts +100 -0
- package/dist/transfer.d.ts +259 -0
- package/package.json +108 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* trzsz2: https://github.com/zxdong262/trzsz2
|
|
3
|
+
* Copyright(c) 2024 Lonny Wong
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* Pure protocol implementation without fs/browser dependencies.
|
|
7
|
+
*/
|
|
8
|
+
export { trzszVersion } from './comm';
|
|
9
|
+
export type { TrzszFile, TrzszFileReader, TrzszFileWriter, OpenSaveFile, ProgressCallback, TmuxModeType } from './comm';
|
|
10
|
+
export type { TrzszOptions } from './options';
|
|
11
|
+
export { TrzszError } from './comm';
|
|
12
|
+
export { TrzszBuffer } from './buffer';
|
|
13
|
+
export { TrzszTransfer } from './transfer';
|
|
14
|
+
export { TextProgressBar } from './progress';
|
|
15
|
+
export { strToUint8, uint8ToStr, strToArrBuf, encodeBuffer, decodeBuffer, checkDuplicateNames, isArrayOfType, isVT100End, stripServerOutput, formatSavedFiles, stripTmuxStatusLine, TmuxMode } from './comm';
|
|
16
|
+
export { getEscapeChars, escapeCharsToCodes, escapeData, unescapeData } from './escape';
|
|
17
|
+
export { getEllipsisString } from './progress';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* trzsz2: https://github.com/zxdong262/trzsz2
|
|
3
|
+
* Copyright(c) 2024 Lonny Wong
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* Pure protocol implementation without fs/browser dependencies.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The trzsz options interface.
|
|
10
|
+
*/
|
|
11
|
+
export interface TrzszOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Write the server output to the terminal.
|
|
14
|
+
* @param output - The server output.
|
|
15
|
+
*/
|
|
16
|
+
writeToTerminal?: (output: string | ArrayBuffer | Uint8Array | Blob) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Send the terminal input (aka: user input) to the server.
|
|
19
|
+
* @param input - The terminal input (aka: user input).
|
|
20
|
+
*/
|
|
21
|
+
sendToServer?: (input: string | Uint8Array) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Choose some files to be sent to the server.
|
|
24
|
+
* No need for webshell or which running in a browser.
|
|
25
|
+
* @param directory - choose directories and files, or just files.
|
|
26
|
+
* @return The file paths array to be sent.
|
|
27
|
+
* undefined means the user has cancelled.
|
|
28
|
+
*/
|
|
29
|
+
chooseSendFiles?: (directory?: boolean) => Promise<string[] | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Choose a directory to save the received files.
|
|
32
|
+
* No need for webshell or which running in a browser.
|
|
33
|
+
* @return The directory to save the received files.
|
|
34
|
+
* undefined means the user has cancelled.
|
|
35
|
+
*/
|
|
36
|
+
chooseSaveDirectory?: () => Promise<string | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated A user event may be required to open the save dialog in browsers.
|
|
39
|
+
* No need for nodejs environment ( e.g.: electron preload.js )
|
|
40
|
+
* @param fileName - The file name going to download.
|
|
41
|
+
* @return open the save dialog or cancel the download.
|
|
42
|
+
*/
|
|
43
|
+
requireUserPermission?: (fileName: string) => Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* The columns of terminal.
|
|
46
|
+
*/
|
|
47
|
+
terminalColumns?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Is there a windows shell? Such as `cmd` and `PowerShell`.
|
|
50
|
+
*/
|
|
51
|
+
isWindowsShell?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The timeout in milliseconds for initializing drag and drop files to upload.
|
|
54
|
+
* Default is 3000.
|
|
55
|
+
*/
|
|
56
|
+
dragInitTimeout?: number | undefined | null;
|
|
57
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ProgressCallback } from './comm';
|
|
2
|
+
/**
|
|
3
|
+
* Get ellipsis string if the string is too long.
|
|
4
|
+
* @param str - The input string.
|
|
5
|
+
* @param max - The maximum length.
|
|
6
|
+
* @return The ellipsis string and its length.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEllipsisString(str: string, max: number): {
|
|
9
|
+
sub: string;
|
|
10
|
+
len: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* TextProgressBar class for displaying file transfer progress.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TextProgressBar implements ProgressCallback {
|
|
16
|
+
private readonly writer;
|
|
17
|
+
private lastUpdateTime;
|
|
18
|
+
private columns;
|
|
19
|
+
private fileCount;
|
|
20
|
+
private fileIdx;
|
|
21
|
+
private fileName;
|
|
22
|
+
private fileSize;
|
|
23
|
+
private fileStep;
|
|
24
|
+
private startTime;
|
|
25
|
+
private tmuxPaneColumns;
|
|
26
|
+
private firstWrite;
|
|
27
|
+
private speedCnt;
|
|
28
|
+
private speedIdx;
|
|
29
|
+
private timeArray;
|
|
30
|
+
private stepArray;
|
|
31
|
+
/**
|
|
32
|
+
* Create a TextProgressBar.
|
|
33
|
+
* @param writer - The output writer function.
|
|
34
|
+
* @param columns - The terminal columns.
|
|
35
|
+
* @param tmuxPaneColumns - The tmux pane columns (optional).
|
|
36
|
+
*/
|
|
37
|
+
constructor(writer: (output: string) => void, columns: number, tmuxPaneColumns?: number | undefined);
|
|
38
|
+
/**
|
|
39
|
+
* Set the terminal columns.
|
|
40
|
+
* @param columns - The terminal columns.
|
|
41
|
+
*/
|
|
42
|
+
setTerminalColumns(columns: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Called when the number of files is known.
|
|
45
|
+
* @param num - The number of files.
|
|
46
|
+
*/
|
|
47
|
+
onNum(num: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Called when a file name is known.
|
|
50
|
+
* @param name - The file name.
|
|
51
|
+
*/
|
|
52
|
+
onName(name: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Called when the file size is known.
|
|
55
|
+
* @param size - The file size.
|
|
56
|
+
*/
|
|
57
|
+
onSize(size: number): void;
|
|
58
|
+
/**
|
|
59
|
+
* Called when a step is completed.
|
|
60
|
+
* @param step - The step number.
|
|
61
|
+
*/
|
|
62
|
+
onStep(step: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Hide the cursor.
|
|
65
|
+
*/
|
|
66
|
+
hideCursor(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Show the cursor.
|
|
69
|
+
*/
|
|
70
|
+
showCursor(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Show the progress.
|
|
73
|
+
*/
|
|
74
|
+
private showProgress;
|
|
75
|
+
/**
|
|
76
|
+
* Get the current transfer speed.
|
|
77
|
+
* @param now - The current time.
|
|
78
|
+
* @return The speed in bytes per second.
|
|
79
|
+
*/
|
|
80
|
+
private getSpeed;
|
|
81
|
+
/**
|
|
82
|
+
* Get the progress text.
|
|
83
|
+
* @param percentage - The percentage string.
|
|
84
|
+
* @param total - The total string.
|
|
85
|
+
* @param speed - The speed string.
|
|
86
|
+
* @param eta - The ETA string.
|
|
87
|
+
* @return The progress text.
|
|
88
|
+
*/
|
|
89
|
+
private getProgressText;
|
|
90
|
+
/**
|
|
91
|
+
* Get the progress bar string.
|
|
92
|
+
* @param len - The length of the bar.
|
|
93
|
+
* @return The progress bar string.
|
|
94
|
+
*/
|
|
95
|
+
private getProgressBar;
|
|
96
|
+
/**
|
|
97
|
+
* Called when the transfer is done.
|
|
98
|
+
*/
|
|
99
|
+
onDone(): void;
|
|
100
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { OpenSaveFile, TrzszFileReader, ProgressCallback } from './comm';
|
|
2
|
+
/**
|
|
3
|
+
* TrzszTransfer class for handling file transfer protocol.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TrzszTransfer {
|
|
6
|
+
private readonly buffer;
|
|
7
|
+
private readonly writer;
|
|
8
|
+
private readonly isWindowsShell;
|
|
9
|
+
private remoteIsWindows;
|
|
10
|
+
private lastInputTime;
|
|
11
|
+
private readonly openedFiles;
|
|
12
|
+
private readonly createdFiles;
|
|
13
|
+
private tmuxOutputJunk;
|
|
14
|
+
private cleanTimeoutInMilliseconds;
|
|
15
|
+
private transferConfig;
|
|
16
|
+
private stopped;
|
|
17
|
+
private maxChunkTimeInMilliseconds;
|
|
18
|
+
private protocolNewline;
|
|
19
|
+
/**
|
|
20
|
+
* Create a TrzszTransfer.
|
|
21
|
+
* @param writer - The output writer function.
|
|
22
|
+
* @param isWindowsShell - Whether the shell is Windows.
|
|
23
|
+
*/
|
|
24
|
+
constructor(writer: (data: string | Uint8Array) => void, isWindowsShell?: boolean);
|
|
25
|
+
/**
|
|
26
|
+
* Cleanup resources.
|
|
27
|
+
*/
|
|
28
|
+
cleanup(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Add received data to the buffer.
|
|
31
|
+
* @param data - The received data.
|
|
32
|
+
*/
|
|
33
|
+
addReceivedData(data: string | ArrayBuffer | Uint8Array | Blob): void;
|
|
34
|
+
/**
|
|
35
|
+
* Stop transferring.
|
|
36
|
+
*/
|
|
37
|
+
stopTransferring(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Clean input buffer.
|
|
40
|
+
* @param timeoutInMilliseconds - The timeout in milliseconds.
|
|
41
|
+
*/
|
|
42
|
+
private cleanInput;
|
|
43
|
+
/**
|
|
44
|
+
* Send a line.
|
|
45
|
+
* @param typ - The type.
|
|
46
|
+
* @param buf - The buffer.
|
|
47
|
+
*/
|
|
48
|
+
private sendLine;
|
|
49
|
+
/**
|
|
50
|
+
* Receive a line.
|
|
51
|
+
* @param expectType - The expected type.
|
|
52
|
+
* @param mayHasJunk - Whether there may be junk.
|
|
53
|
+
*/
|
|
54
|
+
private recvLine;
|
|
55
|
+
/**
|
|
56
|
+
* Receive and check a line.
|
|
57
|
+
* @param expectType - The expected type.
|
|
58
|
+
* @param mayHasJunk - Whether there may be junk.
|
|
59
|
+
*/
|
|
60
|
+
private recvCheck;
|
|
61
|
+
/**
|
|
62
|
+
* Send an integer.
|
|
63
|
+
* @param typ - The type.
|
|
64
|
+
* @param val - The value.
|
|
65
|
+
*/
|
|
66
|
+
private sendInteger;
|
|
67
|
+
/**
|
|
68
|
+
* Receive an integer.
|
|
69
|
+
* @param typ - The type.
|
|
70
|
+
* @param mayHasJunk - Whether there may be junk.
|
|
71
|
+
*/
|
|
72
|
+
private recvInteger;
|
|
73
|
+
/**
|
|
74
|
+
* Check an integer.
|
|
75
|
+
* @param expect - The expected value.
|
|
76
|
+
*/
|
|
77
|
+
private checkInteger;
|
|
78
|
+
/**
|
|
79
|
+
* Send a string.
|
|
80
|
+
* @param typ - The type.
|
|
81
|
+
* @param str - The string.
|
|
82
|
+
*/
|
|
83
|
+
private sendString;
|
|
84
|
+
/**
|
|
85
|
+
* Receive a string.
|
|
86
|
+
* @param typ - The type.
|
|
87
|
+
* @param mayHasJunk - Whether there may be junk.
|
|
88
|
+
*/
|
|
89
|
+
private recvString;
|
|
90
|
+
/**
|
|
91
|
+
* Check a string.
|
|
92
|
+
* @param expect - The expected string.
|
|
93
|
+
*/
|
|
94
|
+
protected checkString(expect: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Send binary data.
|
|
97
|
+
* @param typ - The type.
|
|
98
|
+
* @param buf - The buffer.
|
|
99
|
+
*/
|
|
100
|
+
private sendBinary;
|
|
101
|
+
/**
|
|
102
|
+
* Receive binary data.
|
|
103
|
+
* @param typ - The type.
|
|
104
|
+
* @param mayHasJunk - Whether there may be junk.
|
|
105
|
+
*/
|
|
106
|
+
private recvBinary;
|
|
107
|
+
/**
|
|
108
|
+
* Check binary data.
|
|
109
|
+
* @param expect - The expected buffer.
|
|
110
|
+
*/
|
|
111
|
+
private checkBinary;
|
|
112
|
+
/**
|
|
113
|
+
* Send data.
|
|
114
|
+
* @param data - The data.
|
|
115
|
+
* @param binary - Whether to use binary mode.
|
|
116
|
+
* @param escapeCodes - The escape codes.
|
|
117
|
+
*/
|
|
118
|
+
private sendData;
|
|
119
|
+
/**
|
|
120
|
+
* Receive data.
|
|
121
|
+
* @param binary - Whether to use binary mode.
|
|
122
|
+
* @param escapeCodes - The escape codes.
|
|
123
|
+
* @param timeoutInMilliseconds - The timeout in milliseconds.
|
|
124
|
+
*/
|
|
125
|
+
private recvData;
|
|
126
|
+
/**
|
|
127
|
+
* Send action.
|
|
128
|
+
* @param confirm - Whether to confirm.
|
|
129
|
+
* @param remoteIsWindows - Whether the remote is Windows.
|
|
130
|
+
*/
|
|
131
|
+
sendAction(confirm: boolean, remoteIsWindows: boolean): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Receive action.
|
|
134
|
+
*/
|
|
135
|
+
recvAction(): Promise<Record<string, unknown>>;
|
|
136
|
+
/**
|
|
137
|
+
* Send config.
|
|
138
|
+
* @param args - The config arguments.
|
|
139
|
+
* @param escapeChars - The escape characters.
|
|
140
|
+
* @param tmuxMode - The tmux mode.
|
|
141
|
+
* @param tmuxPaneWidth - The tmux pane width.
|
|
142
|
+
*/
|
|
143
|
+
sendConfig(args: Record<string, unknown>, escapeChars: string[][], tmuxMode: number, tmuxPaneWidth: number): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Receive config.
|
|
146
|
+
*/
|
|
147
|
+
recvConfig(): Promise<Record<string, unknown>>;
|
|
148
|
+
/**
|
|
149
|
+
* Send client exit.
|
|
150
|
+
* @param msg - The message.
|
|
151
|
+
*/
|
|
152
|
+
clientExit(msg: string): Promise<void>;
|
|
153
|
+
/**
|
|
154
|
+
* Receive exit.
|
|
155
|
+
*/
|
|
156
|
+
recvExit(): Promise<string>;
|
|
157
|
+
/**
|
|
158
|
+
* Delete created files.
|
|
159
|
+
*/
|
|
160
|
+
private deleteCreatedFiles;
|
|
161
|
+
/**
|
|
162
|
+
* Handle client error.
|
|
163
|
+
* @param err - The error.
|
|
164
|
+
*/
|
|
165
|
+
clientError(err: Error): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Handle server error.
|
|
168
|
+
* @param err - The error.
|
|
169
|
+
*/
|
|
170
|
+
serverError(err: Error): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Server exit - to be implemented by subclass or user.
|
|
173
|
+
* @param msg - The message.
|
|
174
|
+
*/
|
|
175
|
+
serverExit(_msg: string): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Send file number.
|
|
178
|
+
* @param num - The number of files.
|
|
179
|
+
* @param progressCallback - The progress callback.
|
|
180
|
+
*/
|
|
181
|
+
private sendFileNum;
|
|
182
|
+
/**
|
|
183
|
+
* Send file name.
|
|
184
|
+
* @param file - The file reader.
|
|
185
|
+
* @param directory - Whether it's a directory.
|
|
186
|
+
* @param progressCallback - The progress callback.
|
|
187
|
+
*/
|
|
188
|
+
private sendFileName;
|
|
189
|
+
/**
|
|
190
|
+
* Send file size.
|
|
191
|
+
* @param size - The file size.
|
|
192
|
+
* @param progressCallback - The progress callback.
|
|
193
|
+
*/
|
|
194
|
+
private sendFileSize;
|
|
195
|
+
/**
|
|
196
|
+
* Send file data.
|
|
197
|
+
* @param file - The file reader.
|
|
198
|
+
* @param size - The file size.
|
|
199
|
+
* @param binary - Whether to use binary mode.
|
|
200
|
+
* @param escapeCodes - The escape codes.
|
|
201
|
+
* @param maxBufSize - The maximum buffer size.
|
|
202
|
+
* @param progressCallback - The progress callback.
|
|
203
|
+
*/
|
|
204
|
+
private sendFileData;
|
|
205
|
+
/**
|
|
206
|
+
* Send file MD5.
|
|
207
|
+
* @param digest - The MD5 digest.
|
|
208
|
+
* @param progressCallback - The progress callback.
|
|
209
|
+
*/
|
|
210
|
+
private sendFileMD5;
|
|
211
|
+
/**
|
|
212
|
+
* Send files.
|
|
213
|
+
* @param files - The file readers.
|
|
214
|
+
* @param progressCallback - The progress callback.
|
|
215
|
+
*/
|
|
216
|
+
sendFiles(files: TrzszFileReader[], progressCallback: ProgressCallback | null): Promise<string[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Receive file number.
|
|
219
|
+
* @param progressCallback - The progress callback.
|
|
220
|
+
*/
|
|
221
|
+
private recvFileNum;
|
|
222
|
+
/**
|
|
223
|
+
* Receive file name.
|
|
224
|
+
* @param saveParam - The save parameter.
|
|
225
|
+
* @param openSaveFile - The open save file function.
|
|
226
|
+
* @param directory - Whether it's a directory.
|
|
227
|
+
* @param overwrite - Whether to overwrite.
|
|
228
|
+
* @param progressCallback - The progress callback.
|
|
229
|
+
*/
|
|
230
|
+
private recvFileName;
|
|
231
|
+
/**
|
|
232
|
+
* Receive file size.
|
|
233
|
+
* @param progressCallback - The progress callback.
|
|
234
|
+
*/
|
|
235
|
+
private recvFileSize;
|
|
236
|
+
/**
|
|
237
|
+
* Receive file data.
|
|
238
|
+
* @param file - The file writer.
|
|
239
|
+
* @param size - The file size.
|
|
240
|
+
* @param binary - Whether to use binary mode.
|
|
241
|
+
* @param escapeCodes - The escape codes.
|
|
242
|
+
* @param timeoutInMilliseconds - The timeout in milliseconds.
|
|
243
|
+
* @param progressCallback - The progress callback.
|
|
244
|
+
*/
|
|
245
|
+
private recvFileData;
|
|
246
|
+
/**
|
|
247
|
+
* Receive file MD5.
|
|
248
|
+
* @param digest - The MD5 digest.
|
|
249
|
+
* @param progressCallback - The progress callback.
|
|
250
|
+
*/
|
|
251
|
+
private recvFileMD5;
|
|
252
|
+
/**
|
|
253
|
+
* Receive files.
|
|
254
|
+
* @param saveParam - The save parameter.
|
|
255
|
+
* @param openSaveFile - The open save file function.
|
|
256
|
+
* @param progressCallback - The progress callback.
|
|
257
|
+
*/
|
|
258
|
+
recvFiles(saveParam: unknown, openSaveFile: OpenSaveFile, progressCallback: ProgressCallback | null): Promise<string[]>;
|
|
259
|
+
}
|
package/dist/comm.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* trzsz2: https://github.com/zxdong262/trzsz2
|
|
3
|
+
* Copyright(c) 2024 Lonny Wong
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* Pure protocol implementation without fs/browser dependencies.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* trzsz version
|
|
10
|
+
*/
|
|
11
|
+
export declare const trzszVersion = "2.0.0";
|
|
12
|
+
/**
|
|
13
|
+
* Convert a string to Uint8Array.
|
|
14
|
+
* @param {string} str - The input string.
|
|
15
|
+
* @return {Uint8Array} The resulting Uint8Array.
|
|
16
|
+
*/
|
|
17
|
+
export declare function strToUint8(str: string): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a Uint8Array to string.
|
|
20
|
+
* @param {Uint8Array} buf - The input buffer.
|
|
21
|
+
* @param {string} encoding - The encoding to use.
|
|
22
|
+
* @return {Promise<string>} The resulting string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function uint8ToStr(buf: Uint8Array, encoding?: string): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Convert a string to ArrayBuffer.
|
|
27
|
+
* @param {string} str - The input string.
|
|
28
|
+
* @return {ArrayBuffer} The resulting ArrayBuffer.
|
|
29
|
+
*/
|
|
30
|
+
export declare function strToArrBuf(str: string): ArrayBuffer;
|
|
31
|
+
/**
|
|
32
|
+
* Encode a buffer (compress and base64).
|
|
33
|
+
* @param {string | Uint8Array} buf - The input buffer.
|
|
34
|
+
* @return {string} The encoded string.
|
|
35
|
+
*/
|
|
36
|
+
export declare function encodeBuffer(buf: string | Uint8Array): string;
|
|
37
|
+
/**
|
|
38
|
+
* Decode a buffer (base64 and decompress).
|
|
39
|
+
* @param {string} buf - The encoded string.
|
|
40
|
+
* @return {Uint8Array} The decoded buffer.
|
|
41
|
+
*/
|
|
42
|
+
export declare function decodeBuffer(buf: string): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Custom error class for trzsz operations.
|
|
45
|
+
*/
|
|
46
|
+
export declare class TrzszError extends Error {
|
|
47
|
+
private readonly type;
|
|
48
|
+
private readonly trace;
|
|
49
|
+
constructor(message: string, type?: string | null, trace?: boolean);
|
|
50
|
+
/**
|
|
51
|
+
* Check if the error should include traceback.
|
|
52
|
+
* @return {boolean} True if traceback should be included.
|
|
53
|
+
*/
|
|
54
|
+
isTraceBack(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Check if the error is a remote exit.
|
|
57
|
+
* @return {boolean} True if remote exit.
|
|
58
|
+
*/
|
|
59
|
+
isRemoteExit(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Check if the error is a remote failure.
|
|
62
|
+
* @return {boolean} True if remote failure.
|
|
63
|
+
*/
|
|
64
|
+
isRemoteFail(): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Check if the error indicates stop and delete.
|
|
67
|
+
* @return {boolean} True if stop and delete.
|
|
68
|
+
*/
|
|
69
|
+
isStopAndDelete(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Get the error message.
|
|
72
|
+
* @param {Error} err - The error object.
|
|
73
|
+
* @return {string} The error message.
|
|
74
|
+
*/
|
|
75
|
+
static getErrorMessage(err: Error): string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Interface for trzsz file operations.
|
|
79
|
+
*/
|
|
80
|
+
export interface TrzszFile {
|
|
81
|
+
closeFile: () => void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Interface for trzsz file reader.
|
|
85
|
+
*/
|
|
86
|
+
export interface TrzszFileReader extends TrzszFile {
|
|
87
|
+
getPathId: () => number;
|
|
88
|
+
getRelPath: () => string[];
|
|
89
|
+
isDir: () => boolean;
|
|
90
|
+
getSize: () => number;
|
|
91
|
+
readFile: (buf: ArrayBuffer) => Promise<Uint8Array>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Interface for trzsz file writer.
|
|
95
|
+
*/
|
|
96
|
+
export interface TrzszFileWriter extends TrzszFile {
|
|
97
|
+
getFileName: () => string;
|
|
98
|
+
getLocalName: () => string;
|
|
99
|
+
isDir: () => boolean;
|
|
100
|
+
writeFile: (buf: Uint8Array) => Promise<void>;
|
|
101
|
+
deleteFile: () => Promise<string>;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Type for opening save file.
|
|
105
|
+
*/
|
|
106
|
+
export type OpenSaveFile = (saveParam: any, fileName: string, directory: boolean, overwrite: boolean) => Promise<TrzszFileWriter>;
|
|
107
|
+
/**
|
|
108
|
+
* Interface for progress callback.
|
|
109
|
+
*/
|
|
110
|
+
export interface ProgressCallback {
|
|
111
|
+
onNum: (num: number) => void;
|
|
112
|
+
onName: (name: string) => void;
|
|
113
|
+
onSize: (size: number) => void;
|
|
114
|
+
onStep: (step: number) => void;
|
|
115
|
+
onDone: () => void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check for duplicate file names.
|
|
119
|
+
* @param {TrzszFileReader[]} files - The files to check.
|
|
120
|
+
*/
|
|
121
|
+
export declare function checkDuplicateNames(files: TrzszFileReader[]): void;
|
|
122
|
+
/**
|
|
123
|
+
* Check if an array contains only elements of a specific type.
|
|
124
|
+
* @param {any} arr - The array to check.
|
|
125
|
+
* @param {string} type - The type to check for.
|
|
126
|
+
* @return {boolean} True if all elements are of the specified type.
|
|
127
|
+
*/
|
|
128
|
+
export declare function isArrayOfType(arr: any, type: string): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Check if a character is a VT100 end character.
|
|
131
|
+
* @param {number} c - The character code.
|
|
132
|
+
* @return {boolean} True if it's a VT100 end character.
|
|
133
|
+
*/
|
|
134
|
+
export declare function isVT100End(c: number): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Strip VT100 escape sequences from server output.
|
|
137
|
+
* @param {string | ArrayBuffer | Uint8Array | Blob} output - The server output.
|
|
138
|
+
* @return {string | ArrayBuffer | Uint8Array | Blob} The stripped output.
|
|
139
|
+
*/
|
|
140
|
+
export declare function stripServerOutput(output: string | ArrayBuffer | Uint8Array | Blob): string | ArrayBuffer | Uint8Array | Blob;
|
|
141
|
+
/**
|
|
142
|
+
* Tmux mode constants.
|
|
143
|
+
*/
|
|
144
|
+
export declare const TmuxMode: {
|
|
145
|
+
readonly NoTmux: 0;
|
|
146
|
+
readonly TmuxNormalMode: 1;
|
|
147
|
+
readonly TmuxControlMode: 2;
|
|
148
|
+
};
|
|
149
|
+
export type TmuxModeType = (typeof TmuxMode)[keyof typeof TmuxMode];
|
|
150
|
+
/**
|
|
151
|
+
* Format saved files message.
|
|
152
|
+
* @param {string[]} fileNames - The file names.
|
|
153
|
+
* @param {string} destPath - The destination path.
|
|
154
|
+
* @return {string} The formatted message.
|
|
155
|
+
*/
|
|
156
|
+
export declare function formatSavedFiles(fileNames: string[], destPath: string): string;
|
|
157
|
+
/**
|
|
158
|
+
* Strip tmux status line from buffer.
|
|
159
|
+
* @param {string} buf - The input buffer.
|
|
160
|
+
* @return {string} The stripped buffer.
|
|
161
|
+
*/
|
|
162
|
+
export declare function stripTmuxStatusLine(buf: string): string;
|
package/dist/escape.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* trzsz2: https://github.com/zxdong262/trzsz2
|
|
3
|
+
* Copyright(c) 2024 Lonny Wong
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* Pure protocol implementation without fs/browser dependencies.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Get escape characters for trzsz protocol.
|
|
10
|
+
* @param escapeAll - Whether to escape all special characters.
|
|
11
|
+
* @return Array of escape character pairs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEscapeChars(escapeAll: boolean): string[][];
|
|
14
|
+
/**
|
|
15
|
+
* Convert escape characters to codes.
|
|
16
|
+
* @param escapeChars - Array of escape character pairs.
|
|
17
|
+
* @return Array of escape code triplets.
|
|
18
|
+
*/
|
|
19
|
+
export declare function escapeCharsToCodes(escapeChars: string[][]): number[][];
|
|
20
|
+
/**
|
|
21
|
+
* Escape data using escape codes.
|
|
22
|
+
* @param data - The data to escape.
|
|
23
|
+
* @param escapeCodes - Array of escape code triplets.
|
|
24
|
+
* @return The escaped data.
|
|
25
|
+
*/
|
|
26
|
+
export declare function escapeData(data: Uint8Array, escapeCodes: number[][]): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Unescape data using escape codes.
|
|
29
|
+
* @param data - The data to unescape.
|
|
30
|
+
* @param escapeCodes - Array of escape code triplets.
|
|
31
|
+
* @return The unescaped data.
|
|
32
|
+
*/
|
|
33
|
+
export declare function unescapeData(data: Uint8Array, escapeCodes: number[][]): Uint8Array;
|