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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 trzsz2 contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.cn.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# trzsz2
|
|
2
|
+
|
|
3
|
+
[中文](README.cn.md) | [English](README.md)
|
|
4
|
+
|
|
5
|
+
> trzsz.js 的衍生项目,提供纯协议实现,支持 Node.js 和浏览器环境。
|
|
6
|
+
|
|
7
|
+
## 声明
|
|
8
|
+
|
|
9
|
+
**本项目基于 [Lonny Wong](https://github.com/lonnywong) 开发的 [trzsz-js](https://github.com/trzsz/trzsz.js)。**
|
|
10
|
+
|
|
11
|
+
trzsz 协议的所有原始实现功劳归 Lonny Wong 所有。这是一个衍生作品:
|
|
12
|
+
|
|
13
|
+
- 移除了原始代码库中的文件系统 (`fs`) 和浏览器特定依赖
|
|
14
|
+
- 专注于提供适合 Node.js 环境的纯协议实现
|
|
15
|
+
- 通过浏览器构建版本保持浏览器兼容性
|
|
16
|
+
|
|
17
|
+
## 从源码构建
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# 克隆仓库
|
|
21
|
+
git clone https://github.com/zxdong262/trzsz2.git
|
|
22
|
+
cd trzsz2
|
|
23
|
+
|
|
24
|
+
# 安装依赖
|
|
25
|
+
npm install
|
|
26
|
+
|
|
27
|
+
# 构建所有格式
|
|
28
|
+
npm run build
|
|
29
|
+
|
|
30
|
+
# 构建特定格式
|
|
31
|
+
npm run build:esm # 仅 ESM
|
|
32
|
+
npm run build:cjs # 仅 CommonJS
|
|
33
|
+
npm run build:cjs-full # 打包的 CommonJS
|
|
34
|
+
npm run build:browser # 浏览器包
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 测试
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# 运行单元测试
|
|
41
|
+
npm test
|
|
42
|
+
|
|
43
|
+
# 运行集成测试(需要 Docker)
|
|
44
|
+
npm run test:upload
|
|
45
|
+
npm run test:download
|
|
46
|
+
|
|
47
|
+
# 监视模式
|
|
48
|
+
npm run test:watch
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 待办事项
|
|
52
|
+
|
|
53
|
+
- [ ] 浏览器使用文档和示例
|
|
54
|
+
- [ ] 浏览器环境测试和演示
|
|
55
|
+
- [ ] WebRTC 数据通道集成示例
|
|
56
|
+
|
|
57
|
+
## 相关项目
|
|
58
|
+
|
|
59
|
+
- [trzsz-js](https://github.com/trzsz/trzsz.js) - Lonny Wong 开发的原始 trzsz 实现,包含文件系统支持
|
|
60
|
+
- [trzsz](https://github.com/trzsz/trzsz) - trzsz 主项目
|
|
61
|
+
|
|
62
|
+
## 许可证
|
|
63
|
+
|
|
64
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# trzsz2
|
|
2
|
+
|
|
3
|
+
[中文](README.cn.md) | [English](README.md)
|
|
4
|
+
|
|
5
|
+
> trzsz.js's derivative project providing a pure protocol implementation for Node.js and browser environments.
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
**This project is based on [trzsz-js](https://github.com/trzsz/trzsz.js) by [Lonny Wong](https://github.com/lonnywong).**
|
|
10
|
+
|
|
11
|
+
All credits for the original trzsz protocol implementation go to Lonny Wong. This is a derived work that:
|
|
12
|
+
|
|
13
|
+
- Removes file system (`fs`) and browser-specific dependencies from the original codebase
|
|
14
|
+
- Focuses on providing a pure protocol implementation suitable for Node.js environments
|
|
15
|
+
- Maintains compatibility with browser usage through the browser build
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install trzsz2
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Building from Source
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Clone the repository
|
|
27
|
+
git clone https://github.com/zxdong262/trzsz2.git
|
|
28
|
+
cd trzsz2
|
|
29
|
+
|
|
30
|
+
# Install dependencies
|
|
31
|
+
npm install
|
|
32
|
+
|
|
33
|
+
# Build all formats
|
|
34
|
+
npm run build
|
|
35
|
+
|
|
36
|
+
# Build specific format
|
|
37
|
+
npm run build:esm # ESM only
|
|
38
|
+
npm run build:cjs # CommonJS only
|
|
39
|
+
npm run build:cjs-full # Bundled CommonJS
|
|
40
|
+
npm run build:browser # Browser bundle
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Testing
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Run unit tests
|
|
47
|
+
npm test
|
|
48
|
+
|
|
49
|
+
# Run integration tests (requires Docker)
|
|
50
|
+
npm run test:upload
|
|
51
|
+
npm run test:download
|
|
52
|
+
|
|
53
|
+
# Watch mode
|
|
54
|
+
npm run test:watch
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## TODO
|
|
58
|
+
|
|
59
|
+
- [ ] Browser usage documentation and examples
|
|
60
|
+
- [ ] Browser environment testing and demos
|
|
61
|
+
- [ ] WebRTC data channel integration example
|
|
62
|
+
|
|
63
|
+
## Related Projects
|
|
64
|
+
|
|
65
|
+
- [trzsz-js](https://github.com/trzsz/trzsz.js) - Original trzsz implementation with file system support by Lonny Wong
|
|
66
|
+
- [trzsz](https://github.com/trzsz/trzsz) - The main trzsz project
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
* TrzszBuffer class for handling buffer operations.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TrzszBuffer {
|
|
12
|
+
private bufArray;
|
|
13
|
+
private resolve;
|
|
14
|
+
private reject;
|
|
15
|
+
private bufHead;
|
|
16
|
+
private bufTail;
|
|
17
|
+
private nextIdx;
|
|
18
|
+
private nextBuf;
|
|
19
|
+
private arrBuf;
|
|
20
|
+
/**
|
|
21
|
+
* Add a buffer to the queue.
|
|
22
|
+
* @param buf - The buffer to add.
|
|
23
|
+
*/
|
|
24
|
+
addBuffer(buf: string | ArrayBuffer | Uint8Array | Blob): void;
|
|
25
|
+
/**
|
|
26
|
+
* Stop the buffer and reject any pending operations.
|
|
27
|
+
*/
|
|
28
|
+
stopBuffer(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Drain all buffers.
|
|
31
|
+
*/
|
|
32
|
+
drainBuffer(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Convert a buffer to Uint8Array.
|
|
35
|
+
* @param buf - The buffer to convert.
|
|
36
|
+
* @return The resulting Uint8Array.
|
|
37
|
+
*/
|
|
38
|
+
private toUint8Array;
|
|
39
|
+
/**
|
|
40
|
+
* Get the next buffer.
|
|
41
|
+
* @return The next buffer.
|
|
42
|
+
*/
|
|
43
|
+
private nextBuffer;
|
|
44
|
+
/**
|
|
45
|
+
* Grow the buffer.
|
|
46
|
+
* @param dst - The destination buffer.
|
|
47
|
+
* @param idx - The current index.
|
|
48
|
+
* @param min - The minimum size needed.
|
|
49
|
+
* @return The grown buffer.
|
|
50
|
+
*/
|
|
51
|
+
private growBuffer;
|
|
52
|
+
/**
|
|
53
|
+
* Append a buffer to another.
|
|
54
|
+
* @param dst - The destination buffer.
|
|
55
|
+
* @param idx - The current index.
|
|
56
|
+
* @param src - The source buffer.
|
|
57
|
+
* @return The resulting buffer.
|
|
58
|
+
*/
|
|
59
|
+
private appendBuffer;
|
|
60
|
+
/**
|
|
61
|
+
* Read a line from the buffer.
|
|
62
|
+
* @return The line.
|
|
63
|
+
*/
|
|
64
|
+
readLine(): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Read binary data from the buffer.
|
|
67
|
+
* @param len - The length to read.
|
|
68
|
+
* @return The binary data.
|
|
69
|
+
*/
|
|
70
|
+
readBinary(len: number): Promise<Uint8Array>;
|
|
71
|
+
/**
|
|
72
|
+
* Read a line on Windows (handles VT100 escape sequences).
|
|
73
|
+
* @return The line.
|
|
74
|
+
*/
|
|
75
|
+
readLineOnWindows(): Promise<string>;
|
|
76
|
+
}
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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
|
+
}
|