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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.cn.md +64 -0
  3. package/README.md +70 -0
  4. package/dist/browser/buffer.d.ts +76 -0
  5. package/dist/browser/comm.d.ts +162 -0
  6. package/dist/browser/escape.d.ts +33 -0
  7. package/dist/browser/index.d.ts +17 -0
  8. package/dist/browser/options.d.ts +57 -0
  9. package/dist/browser/progress.d.ts +100 -0
  10. package/dist/browser/transfer.d.ts +259 -0
  11. package/dist/browser/trzsz2.js +6147 -0
  12. package/dist/browser/trzsz2.js.map +1 -0
  13. package/dist/browser/trzsz2.min.js +19 -0
  14. package/dist/buffer.d.ts +76 -0
  15. package/dist/cjs/buffer.cjs +252 -0
  16. package/dist/cjs/buffer.cjs.map +1 -0
  17. package/dist/cjs/buffer.d.ts +76 -0
  18. package/dist/cjs/comm.cjs +292 -0
  19. package/dist/cjs/comm.cjs.map +1 -0
  20. package/dist/cjs/comm.d.ts +162 -0
  21. package/dist/cjs/escape.cjs +86 -0
  22. package/dist/cjs/escape.cjs.map +1 -0
  23. package/dist/cjs/escape.d.ts +33 -0
  24. package/dist/cjs/index.cjs +30 -0
  25. package/dist/cjs/index.cjs.map +1 -0
  26. package/dist/cjs/index.d.ts +17 -0
  27. package/dist/cjs/node_modules/pako/dist/pako.esm.cjs +4177 -0
  28. package/dist/cjs/node_modules/pako/dist/pako.esm.cjs.map +1 -0
  29. package/dist/cjs/node_modules/ts-md5/dist/esm/md5.cjs +353 -0
  30. package/dist/cjs/node_modules/ts-md5/dist/esm/md5.cjs.map +1 -0
  31. package/dist/cjs/options.d.ts +57 -0
  32. package/dist/cjs/package.json +3 -0
  33. package/dist/cjs/progress.cjs +313 -0
  34. package/dist/cjs/progress.cjs.map +1 -0
  35. package/dist/cjs/progress.d.ts +100 -0
  36. package/dist/cjs/transfer.cjs +706 -0
  37. package/dist/cjs/transfer.cjs.map +1 -0
  38. package/dist/cjs/transfer.d.ts +259 -0
  39. package/dist/cjs-full/buffer.d.ts +76 -0
  40. package/dist/cjs-full/comm.d.ts +162 -0
  41. package/dist/cjs-full/escape.d.ts +33 -0
  42. package/dist/cjs-full/index.cjs +6144 -0
  43. package/dist/cjs-full/index.cjs.map +1 -0
  44. package/dist/cjs-full/index.d.ts +17 -0
  45. package/dist/cjs-full/options.d.ts +57 -0
  46. package/dist/cjs-full/package.json +3 -0
  47. package/dist/cjs-full/progress.d.ts +100 -0
  48. package/dist/cjs-full/transfer.d.ts +259 -0
  49. package/dist/comm.d.ts +162 -0
  50. package/dist/escape.d.ts +33 -0
  51. package/dist/esm/buffer.d.ts +76 -0
  52. package/dist/esm/buffer.js +252 -0
  53. package/dist/esm/buffer.js.map +1 -0
  54. package/dist/esm/comm.d.ts +162 -0
  55. package/dist/esm/comm.js +292 -0
  56. package/dist/esm/comm.js.map +1 -0
  57. package/dist/esm/escape.d.ts +33 -0
  58. package/dist/esm/escape.js +86 -0
  59. package/dist/esm/escape.js.map +1 -0
  60. package/dist/esm/index.d.ts +17 -0
  61. package/dist/esm/index.js +30 -0
  62. package/dist/esm/index.js.map +1 -0
  63. package/dist/esm/node_modules/pako/dist/pako.esm.js +4177 -0
  64. package/dist/esm/node_modules/pako/dist/pako.esm.js.map +1 -0
  65. package/dist/esm/node_modules/ts-md5/dist/esm/md5.js +353 -0
  66. package/dist/esm/node_modules/ts-md5/dist/esm/md5.js.map +1 -0
  67. package/dist/esm/options.d.ts +57 -0
  68. package/dist/esm/package.json +3 -0
  69. package/dist/esm/progress.d.ts +100 -0
  70. package/dist/esm/progress.js +313 -0
  71. package/dist/esm/progress.js.map +1 -0
  72. package/dist/esm/transfer.d.ts +259 -0
  73. package/dist/esm/transfer.js +706 -0
  74. package/dist/esm/transfer.js.map +1 -0
  75. package/dist/index.d.ts +17 -0
  76. package/dist/options.d.ts +57 -0
  77. package/dist/progress.d.ts +100 -0
  78. package/dist/transfer.d.ts +259 -0
  79. package/package.json +108 -0
@@ -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,252 @@
1
+ import { TrzszError, strToUint8, uint8ToStr, isVT100End } from "./comm.js";
2
+ function isTrzszLetter(c) {
3
+ if (c >= 97 && c <= 122) {
4
+ return true;
5
+ }
6
+ if (c >= 65 && c <= 90) {
7
+ return true;
8
+ }
9
+ if (c >= 48 && c <= 57) {
10
+ return true;
11
+ }
12
+ if (c === 35 || c === 58 || c === 43 || c === 47 || c === 61) {
13
+ return true;
14
+ }
15
+ return false;
16
+ }
17
+ class TrzszBuffer {
18
+ constructor() {
19
+ this.bufArray = [];
20
+ this.resolve = null;
21
+ this.reject = null;
22
+ this.bufHead = 0;
23
+ this.bufTail = 0;
24
+ this.nextIdx = 0;
25
+ this.nextBuf = null;
26
+ this.arrBuf = new ArrayBuffer(128);
27
+ }
28
+ /**
29
+ * Add a buffer to the queue.
30
+ * @param buf - The buffer to add.
31
+ */
32
+ addBuffer(buf) {
33
+ this.bufArray[this.bufTail++] = buf;
34
+ if (this.resolve != null) {
35
+ this.resolve();
36
+ this.resolve = null;
37
+ this.reject = null;
38
+ }
39
+ }
40
+ /**
41
+ * Stop the buffer and reject any pending operations.
42
+ */
43
+ stopBuffer() {
44
+ if (this.reject != null) {
45
+ this.reject(new TrzszError("Stopped"));
46
+ this.reject = null;
47
+ this.resolve = null;
48
+ }
49
+ }
50
+ /**
51
+ * Drain all buffers.
52
+ */
53
+ drainBuffer() {
54
+ this.bufArray = [];
55
+ this.bufHead = 0;
56
+ this.bufTail = 0;
57
+ }
58
+ /**
59
+ * Convert a buffer to Uint8Array.
60
+ * @param buf - The buffer to convert.
61
+ * @return The resulting Uint8Array.
62
+ */
63
+ async toUint8Array(buf) {
64
+ if (typeof buf === "string") {
65
+ return strToUint8(buf);
66
+ } else if (buf instanceof ArrayBuffer) {
67
+ return new Uint8Array(buf);
68
+ } else if (buf instanceof Uint8Array) {
69
+ return buf;
70
+ } else if (buf instanceof Blob) {
71
+ const buffer = await buf.arrayBuffer();
72
+ return new Uint8Array(buffer);
73
+ } else {
74
+ throw new TrzszError("The buffer type is not supported", null, true);
75
+ }
76
+ }
77
+ /**
78
+ * Get the next buffer.
79
+ * @return The next buffer.
80
+ */
81
+ async nextBuffer() {
82
+ if (this.nextBuf != null && this.nextIdx < this.nextBuf.length) {
83
+ return this.nextBuf.subarray(this.nextIdx);
84
+ }
85
+ if (this.bufHead === this.bufTail) {
86
+ if (this.bufHead !== 0) {
87
+ this.bufHead = 0;
88
+ this.bufTail = 0;
89
+ }
90
+ await new Promise((resolve, reject) => {
91
+ this.resolve = resolve;
92
+ this.reject = reject;
93
+ });
94
+ }
95
+ const buf = this.bufArray[this.bufHead];
96
+ this.bufArray[this.bufHead] = null;
97
+ this.bufHead++;
98
+ if (buf == null) {
99
+ throw new TrzszError("Unexpected null buffer");
100
+ }
101
+ this.nextBuf = await this.toUint8Array(buf);
102
+ this.nextIdx = 0;
103
+ return this.nextBuf;
104
+ }
105
+ /**
106
+ * Grow the buffer.
107
+ * @param dst - The destination buffer.
108
+ * @param idx - The current index.
109
+ * @param min - The minimum size needed.
110
+ * @return The grown buffer.
111
+ */
112
+ growBuffer(dst, idx, min) {
113
+ const len = Math.max(dst.length * 2, idx + min);
114
+ this.arrBuf = new ArrayBuffer(len);
115
+ const buf = new Uint8Array(this.arrBuf);
116
+ buf.set(dst.subarray(0, idx));
117
+ return buf;
118
+ }
119
+ /**
120
+ * Append a buffer to another.
121
+ * @param dst - The destination buffer.
122
+ * @param idx - The current index.
123
+ * @param src - The source buffer.
124
+ * @return The resulting buffer.
125
+ */
126
+ appendBuffer(dst, idx, src) {
127
+ const buf = dst.length >= idx + src.length ? dst : this.growBuffer(dst, idx, src.length);
128
+ buf.set(src, idx);
129
+ return buf;
130
+ }
131
+ /**
132
+ * Read a line from the buffer.
133
+ * @return The line.
134
+ */
135
+ async readLine() {
136
+ let buf = new Uint8Array(this.arrBuf);
137
+ let len = 0;
138
+ while (true) {
139
+ let next = await this.nextBuffer();
140
+ const newLineIdx = next.indexOf(10);
141
+ if (newLineIdx >= 0) {
142
+ this.nextIdx += newLineIdx + 1;
143
+ next = next.subarray(0, newLineIdx);
144
+ } else {
145
+ this.nextIdx += next.length;
146
+ }
147
+ if (next.includes(3)) {
148
+ throw new TrzszError("Interrupted");
149
+ }
150
+ buf = this.appendBuffer(buf, len, next);
151
+ len += next.length;
152
+ if (newLineIdx >= 0) {
153
+ return await uint8ToStr(buf.subarray(0, len));
154
+ }
155
+ }
156
+ }
157
+ /**
158
+ * Read binary data from the buffer.
159
+ * @param len - The length to read.
160
+ * @return The binary data.
161
+ */
162
+ async readBinary(len) {
163
+ if (this.arrBuf.byteLength < len) {
164
+ this.arrBuf = new ArrayBuffer(len);
165
+ }
166
+ const buf = new Uint8Array(this.arrBuf, 0, len);
167
+ let idx = 0;
168
+ while (idx < len) {
169
+ const left = len - idx;
170
+ let next = await this.nextBuffer();
171
+ if (next.length > left) {
172
+ this.nextIdx += left;
173
+ next = next.subarray(0, left);
174
+ } else {
175
+ this.nextIdx += next.length;
176
+ }
177
+ buf.set(next, idx);
178
+ idx += next.length;
179
+ }
180
+ return buf;
181
+ }
182
+ /**
183
+ * Read a line on Windows (handles VT100 escape sequences).
184
+ * @return The line.
185
+ */
186
+ async readLineOnWindows() {
187
+ let buf = new Uint8Array(this.arrBuf);
188
+ let lastByte = 27;
189
+ let skipVT100 = false;
190
+ let hasNewline = false;
191
+ let mayDuplicate = false;
192
+ let hasCursorHome = false;
193
+ let preHasCursorHome = false;
194
+ let idx = 0;
195
+ while (true) {
196
+ let next = await this.nextBuffer();
197
+ const newLineIdx = next.indexOf(33);
198
+ if (newLineIdx >= 0) {
199
+ this.nextIdx += newLineIdx + 1;
200
+ next = next.subarray(0, newLineIdx);
201
+ } else {
202
+ this.nextIdx += next.length;
203
+ }
204
+ for (let i = 0; i < next.length; i++) {
205
+ const c = next[i];
206
+ if (c === 3) {
207
+ throw new TrzszError("Interrupted");
208
+ }
209
+ if (c === 10) {
210
+ hasNewline = true;
211
+ }
212
+ if (skipVT100) {
213
+ if (isVT100End(c)) {
214
+ skipVT100 = false;
215
+ if (c === 72 && lastByte >= 48 && lastByte <= 57) {
216
+ mayDuplicate = true;
217
+ }
218
+ }
219
+ if (lastByte === 91 && c === 72) {
220
+ hasCursorHome = true;
221
+ }
222
+ lastByte = c;
223
+ } else if (c === 27) {
224
+ skipVT100 = true;
225
+ lastByte = c;
226
+ } else if (isTrzszLetter(c)) {
227
+ if (mayDuplicate) {
228
+ mayDuplicate = false;
229
+ if (hasNewline && idx > 0 && (c === buf[idx - 1] || preHasCursorHome)) {
230
+ buf[idx - 1] = c;
231
+ continue;
232
+ }
233
+ }
234
+ if (idx >= buf.length) {
235
+ buf = this.growBuffer(buf, idx, next.length);
236
+ }
237
+ buf[idx++] = c;
238
+ preHasCursorHome = hasCursorHome;
239
+ hasCursorHome = false;
240
+ hasNewline = false;
241
+ }
242
+ }
243
+ if (newLineIdx >= 0 && idx > 0 && !skipVT100) {
244
+ return await uint8ToStr(buf.subarray(0, idx));
245
+ }
246
+ }
247
+ }
248
+ }
249
+ export {
250
+ TrzszBuffer
251
+ };
252
+ //# sourceMappingURL=buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer.js","sources":["../../src/buffer.ts"],"sourcesContent":["/**\n * trzsz2: https://github.com/zxdong262/trzsz2\n * Copyright(c) 2024 Lonny Wong\n * @license MIT\n *\n * Pure protocol implementation without fs/browser dependencies.\n */\n\nimport { strToUint8, uint8ToStr, TrzszError, isVT100End } from './comm'\n\n/**\n * Check if a character is a trzsz letter.\n * @param c - The character code.\n * @return True if it's a trzsz letter.\n */\nfunction isTrzszLetter (c: number): boolean {\n if (c >= 0x61 && c <= 0x7a) {\n // 'a' <= c && c <= 'z'\n return true\n }\n if (c >= 0x41 && c <= 0x5a) {\n // 'A' <= c && c <= 'Z'\n return true\n }\n if (c >= 0x30 && c <= 0x39) {\n // '0' <= c && c <= '9'\n return true\n }\n if (c === 0x23 || c === 0x3a || c === 0x2b || c === 0x2f || c === 0x3d) {\n // c == '#' || c == ':' || c == '+' || c == '/' || c == '='\n return true\n }\n return false\n}\n\n/**\n * TrzszBuffer class for handling buffer operations.\n */\nexport class TrzszBuffer {\n private bufArray: Array<string | ArrayBuffer | Uint8Array | Blob | null> = []\n private resolve: (() => void) | null = null\n private reject: ((err: Error) => void) | null = null\n private bufHead: number = 0\n private bufTail: number = 0\n private nextIdx: number = 0\n private nextBuf: Uint8Array | null = null\n private arrBuf: ArrayBuffer = new ArrayBuffer(128)\n\n /**\n * Add a buffer to the queue.\n * @param buf - The buffer to add.\n */\n public addBuffer (buf: string | ArrayBuffer | Uint8Array | Blob): void {\n this.bufArray[this.bufTail++] = buf\n if (this.resolve != null) {\n this.resolve()\n this.resolve = null\n this.reject = null\n }\n }\n\n /**\n * Stop the buffer and reject any pending operations.\n */\n public stopBuffer (): void {\n if (this.reject != null) {\n this.reject(new TrzszError('Stopped'))\n this.reject = null\n this.resolve = null\n }\n }\n\n /**\n * Drain all buffers.\n */\n public drainBuffer (): void {\n this.bufArray = []\n this.bufHead = 0\n this.bufTail = 0\n }\n\n /**\n * Convert a buffer to Uint8Array.\n * @param buf - The buffer to convert.\n * @return The resulting Uint8Array.\n */\n private async toUint8Array (buf: string | ArrayBuffer | Uint8Array | Blob): Promise<Uint8Array> {\n if (typeof buf === 'string') {\n return strToUint8(buf)\n } else if (buf instanceof ArrayBuffer) {\n return new Uint8Array(buf)\n } else if (buf instanceof Uint8Array) {\n return buf\n } else if (buf instanceof Blob) {\n const buffer = await buf.arrayBuffer()\n return new Uint8Array(buffer)\n } else {\n throw new TrzszError('The buffer type is not supported', null, true)\n }\n }\n\n /**\n * Get the next buffer.\n * @return The next buffer.\n */\n private async nextBuffer (): Promise<Uint8Array> {\n if ((this.nextBuf != null) && this.nextIdx < this.nextBuf.length) {\n return this.nextBuf.subarray(this.nextIdx)\n }\n if (this.bufHead === this.bufTail) {\n if (this.bufHead !== 0) {\n this.bufHead = 0\n this.bufTail = 0\n }\n await new Promise<void>((resolve, reject) => {\n this.resolve = resolve\n this.reject = reject\n })\n }\n const buf = this.bufArray[this.bufHead]\n this.bufArray[this.bufHead] = null\n this.bufHead++\n if (buf == null) {\n throw new TrzszError('Unexpected null buffer')\n }\n this.nextBuf = await this.toUint8Array(buf)\n this.nextIdx = 0\n return this.nextBuf\n }\n\n /**\n * Grow the buffer.\n * @param dst - The destination buffer.\n * @param idx - The current index.\n * @param min - The minimum size needed.\n * @return The grown buffer.\n */\n private growBuffer (dst: Uint8Array, idx: number, min: number): Uint8Array {\n const len = Math.max(dst.length * 2, idx + min)\n this.arrBuf = new ArrayBuffer(len)\n const buf = new Uint8Array(this.arrBuf)\n buf.set(dst.subarray(0, idx))\n return buf\n }\n\n /**\n * Append a buffer to another.\n * @param dst - The destination buffer.\n * @param idx - The current index.\n * @param src - The source buffer.\n * @return The resulting buffer.\n */\n private appendBuffer (dst: Uint8Array, idx: number, src: Uint8Array): Uint8Array {\n const buf = dst.length >= idx + src.length ? dst : this.growBuffer(dst, idx, src.length)\n buf.set(src, idx)\n return buf\n }\n\n /**\n * Read a line from the buffer.\n * @return The line.\n */\n public async readLine (): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n let buf = new Uint8Array(this.arrBuf) as Uint8Array\n let len = 0\n while (true) {\n let next = await this.nextBuffer()\n const newLineIdx = next.indexOf(0x0a) // '\\n'\n if (newLineIdx >= 0) {\n this.nextIdx += newLineIdx + 1 // +1 to ignore the '\\n'\n next = next.subarray(0, newLineIdx)\n } else {\n this.nextIdx += next.length\n }\n if (next.includes(0x03)) {\n // `ctrl + c` to interrupt\n throw new TrzszError('Interrupted')\n }\n buf = this.appendBuffer(buf, len, next)\n len += next.length\n if (newLineIdx >= 0) {\n return await uint8ToStr(buf.subarray(0, len))\n }\n }\n }\n\n /**\n * Read binary data from the buffer.\n * @param len - The length to read.\n * @return The binary data.\n */\n public async readBinary (len: number): Promise<Uint8Array> {\n if (this.arrBuf.byteLength < len) {\n this.arrBuf = new ArrayBuffer(len)\n }\n const buf = new Uint8Array(this.arrBuf, 0, len)\n let idx = 0\n while (idx < len) {\n const left = len - idx\n let next = await this.nextBuffer()\n if (next.length > left) {\n this.nextIdx += left\n next = next.subarray(0, left)\n } else {\n this.nextIdx += next.length\n }\n buf.set(next, idx)\n idx += next.length\n }\n return buf\n }\n\n /**\n * Read a line on Windows (handles VT100 escape sequences).\n * @return The line.\n */\n public async readLineOnWindows (): Promise<string> {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n let buf = new Uint8Array(this.arrBuf) as Uint8Array\n let lastByte = 0x1b\n let skipVT100 = false\n let hasNewline = false\n let mayDuplicate = false\n let hasCursorHome = false\n let preHasCursorHome = false\n let idx = 0\n while (true) {\n let next = await this.nextBuffer()\n const newLineIdx = next.indexOf(0x21) // '!'\n if (newLineIdx >= 0) {\n this.nextIdx += newLineIdx + 1 // +1 to ignore the '!'\n next = next.subarray(0, newLineIdx)\n } else {\n this.nextIdx += next.length\n }\n for (let i = 0; i < next.length; i++) {\n const c = next[i]\n if (c === 0x03) {\n // `ctrl + c` to interrupt\n throw new TrzszError('Interrupted')\n }\n if (c === 0x0a) {\n hasNewline = true\n }\n if (skipVT100) {\n if (isVT100End(c)) {\n skipVT100 = false\n // moving the cursor may result in duplicate characters\n if (c === 0x48 && lastByte >= 0x30 && lastByte <= 0x39) {\n mayDuplicate = true\n }\n }\n if (lastByte === 0x5b && c === 0x48) {\n hasCursorHome = true\n }\n lastByte = c\n } else if (c === 0x1b) {\n skipVT100 = true\n lastByte = c\n } else if (isTrzszLetter(c)) {\n if (mayDuplicate) {\n mayDuplicate = false\n // skip the duplicate characters, e.g., the \"8\" in \"8\\r\\n\\x1b[25;119H8\".\n if (hasNewline && idx > 0 && (c === buf[idx - 1] || preHasCursorHome)) {\n buf[idx - 1] = c\n continue\n }\n }\n if (idx >= buf.length) {\n buf = this.growBuffer(buf, idx, next.length)\n }\n buf[idx++] = c\n preHasCursorHome = hasCursorHome\n hasCursorHome = false\n hasNewline = false\n }\n }\n if (newLineIdx >= 0 && idx > 0 && !skipVT100) {\n return await uint8ToStr(buf.subarray(0, idx))\n }\n }\n }\n}\n"],"names":[],"mappings":";AAeA,SAAS,cAAe,GAAoB;AAC1C,MAAI,KAAK,MAAQ,KAAK,KAAM;AAE1B,WAAO;AAAA,EACT;AACA,MAAI,KAAK,MAAQ,KAAK,IAAM;AAE1B,WAAO;AAAA,EACT;AACA,MAAI,KAAK,MAAQ,KAAK,IAAM;AAE1B,WAAO;AAAA,EACT;AACA,MAAI,MAAM,MAAQ,MAAM,MAAQ,MAAM,MAAQ,MAAM,MAAQ,MAAM,IAAM;AAEtE,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAKO,MAAM,YAAY;AAAA,EAAlB,cAAA;AACL,SAAQ,WAAmE,CAAA;AAC3E,SAAQ,UAA+B;AACvC,SAAQ,SAAwC;AAChD,SAAQ,UAAkB;AAC1B,SAAQ,UAAkB;AAC1B,SAAQ,UAAkB;AAC1B,SAAQ,UAA6B;AACrC,SAAQ,SAAsB,IAAI,YAAY,GAAG;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1C,UAAW,KAAqD;AACrE,SAAK,SAAS,KAAK,SAAS,IAAI;AAChC,QAAI,KAAK,WAAW,MAAM;AACxB,WAAK,QAAA;AACL,WAAK,UAAU;AACf,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKO,aAAoB;AACzB,QAAI,KAAK,UAAU,MAAM;AACvB,WAAK,OAAO,IAAI,WAAW,SAAS,CAAC;AACrC,WAAK,SAAS;AACd,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKO,cAAqB;AAC1B,SAAK,WAAW,CAAA;AAChB,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAA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C,IAAI;AACf;AAAA,YACF;AAAA,UACF;AACA,cAAI,OAAO,IAAI,QAAQ;AACrB,kBAAM,KAAK,WAAW,KAAK,KAAK,KAAK,MAAM;AAAA,UAC7C;AACA,cAAI,KAAK,IAAI;AACb,6BAAmB;AACnB,0BAAgB;AAChB,uBAAa;AAAA,QACf;AAAA,MACF;AACA,UAAI,cAAc,KAAK,MAAM,KAAK,CAAC,WAAW;AAC5C,eAAO,MAAM,WAAW,IAAI,SAAS,GAAG,GAAG,CAAC;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AACF;"}
@@ -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;