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 @@
1
+ {"version":3,"file":"transfer.js","sources":["../../src/transfer.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 { Md5 } from 'ts-md5'\nimport { TrzszBuffer } from './buffer'\nimport { escapeCharsToCodes, escapeData, unescapeData } from './escape'\nimport {\n trzszVersion,\n uint8ToStr,\n encodeBuffer,\n decodeBuffer,\n TmuxMode,\n TrzszError,\n type TrzszFile,\n type OpenSaveFile,\n type TrzszFileReader,\n type TrzszFileWriter,\n type ProgressCallback,\n stripTmuxStatusLine\n} from './comm'\n\n/**\n * TrzszTransfer class for handling file transfer protocol.\n */\nexport class TrzszTransfer {\n private readonly buffer: TrzszBuffer = new TrzszBuffer()\n private readonly writer: (data: string | Uint8Array) => void\n private readonly isWindowsShell: boolean\n private remoteIsWindows: boolean = false\n private lastInputTime: number = 0\n private readonly openedFiles: TrzszFile[] = []\n private readonly createdFiles: TrzszFileWriter[] = []\n private tmuxOutputJunk: boolean = false\n private cleanTimeoutInMilliseconds: number = 100\n private transferConfig: Record<string, unknown> = {}\n private stopped: boolean = false\n private maxChunkTimeInMilliseconds: number = 0\n private protocolNewline: string = '\\n'\n\n /**\n * Create a TrzszTransfer.\n * @param writer - The output writer function.\n * @param isWindowsShell - Whether the shell is Windows.\n */\n public constructor (writer: (data: string | Uint8Array) => void, isWindowsShell: boolean = false) {\n this.writer = writer\n this.isWindowsShell = isWindowsShell\n }\n\n /**\n * Cleanup resources.\n */\n public cleanup (): void {\n for (const file of this.openedFiles) {\n file.closeFile()\n }\n }\n\n /**\n * Add received data to the buffer.\n * @param data - The received data.\n */\n public addReceivedData (data: string | ArrayBuffer | Uint8Array | Blob): void {\n if (!this.stopped) {\n this.buffer.addBuffer(data)\n }\n this.lastInputTime = Date.now()\n }\n\n /**\n * Stop transferring.\n */\n public async stopTransferring (): Promise<void> {\n this.cleanTimeoutInMilliseconds = Math.max(this.maxChunkTimeInMilliseconds * 2, 500)\n this.stopped = true\n this.buffer.stopBuffer()\n }\n\n /**\n * Clean input buffer.\n * @param timeoutInMilliseconds - The timeout in milliseconds.\n */\n private async cleanInput (timeoutInMilliseconds: number): Promise<void> {\n this.stopped = true\n this.buffer.drainBuffer()\n this.lastInputTime = Date.now()\n while (true) {\n const sleepTime = timeoutInMilliseconds - (Date.now() - this.lastInputTime)\n if (sleepTime <= 0) {\n return\n }\n await new Promise((resolve) => setTimeout(resolve, sleepTime))\n }\n }\n\n /**\n * Send a line.\n * @param typ - The type.\n * @param buf - The buffer.\n */\n private async sendLine (typ: string, buf: string): Promise<void> {\n this.writer(`#${typ}:${buf}${this.protocolNewline}`)\n }\n\n /**\n * Receive a line.\n * @param expectType - The expected type.\n * @param mayHasJunk - Whether there may be junk.\n */\n private async recvLine (expectType: string, mayHasJunk: boolean = false): Promise<string> {\n if (this.stopped) {\n throw new TrzszError('Stopped')\n }\n\n if (this.isWindowsShell || this.remoteIsWindows) {\n let line = await this.buffer.readLineOnWindows()\n const idx = line.lastIndexOf('#' + expectType + ':')\n if (idx >= 0) {\n line = line.substring(idx)\n } else {\n const idx = line.lastIndexOf('#')\n if (idx > 0) {\n line = line.substring(idx)\n }\n }\n return line\n }\n\n let line = await this.buffer.readLine()\n\n if (this.tmuxOutputJunk || mayHasJunk) {\n if (line.length > 0) {\n while (line[line.length - 1] === '\\r') {\n line = line.substring(0, line.length - 1) + (await this.buffer.readLine())\n }\n }\n const idx = line.lastIndexOf('#' + expectType + ':')\n if (idx >= 0) {\n line = line.substring(idx)\n } else {\n const idx = line.lastIndexOf('#')\n if (idx > 0) {\n line = line.substring(idx)\n }\n }\n line = stripTmuxStatusLine(line)\n }\n\n return line\n }\n\n /**\n * Receive and check a line.\n * @param expectType - The expected type.\n * @param mayHasJunk - Whether there may be junk.\n */\n private async recvCheck (expectType: string, mayHasJunk: boolean = false): Promise<string> {\n const line = await this.recvLine(expectType, mayHasJunk)\n const idx = line.indexOf(':')\n if (idx < 1) {\n throw new TrzszError(encodeBuffer(line), 'colon', true)\n }\n const typ = line.substring(1, idx)\n const buf = line.substring(idx + 1)\n if (typ !== expectType) {\n throw new TrzszError(buf, typ, true)\n }\n return buf\n }\n\n /**\n * Send an integer.\n * @param typ - The type.\n * @param val - The value.\n */\n private async sendInteger (typ: string, val: number): Promise<void> {\n await this.sendLine(typ, val.toString())\n }\n\n /**\n * Receive an integer.\n * @param typ - The type.\n * @param mayHasJunk - Whether there may be junk.\n */\n private async recvInteger (typ: string, mayHasJunk: boolean = false): Promise<number> {\n const buf = await this.recvCheck(typ, mayHasJunk)\n return Number(buf)\n }\n\n /**\n * Check an integer.\n * @param expect - The expected value.\n */\n private async checkInteger (expect: number): Promise<void> {\n const result = await this.recvInteger('SUCC')\n if (result !== expect) {\n throw new TrzszError(`Integer check [${result}] <> [${expect}]`, null, true)\n }\n }\n\n /**\n * Send a string.\n * @param typ - The type.\n * @param str - The string.\n */\n private async sendString (typ: string, str: string): Promise<void> {\n await this.sendLine(typ, encodeBuffer(str))\n }\n\n /**\n * Receive a string.\n * @param typ - The type.\n * @param mayHasJunk - Whether there may be junk.\n */\n private async recvString (typ: string, mayHasJunk: boolean = false): Promise<string> {\n const buf = await this.recvCheck(typ, mayHasJunk)\n return await uint8ToStr(decodeBuffer(buf), 'utf8')\n }\n\n /**\n * Check a string.\n * @param expect - The expected string.\n */\n protected async checkString (expect: string): Promise<void> {\n const result = await this.recvString('SUCC')\n if (result !== expect) {\n throw new TrzszError(`String check [${result}] <> [${expect}]`, null, true)\n }\n }\n\n /**\n * Send binary data.\n * @param typ - The type.\n * @param buf - The buffer.\n */\n private async sendBinary (typ: string, buf: Uint8Array): Promise<void> {\n await this.sendLine(typ, encodeBuffer(buf))\n }\n\n /**\n * Receive binary data.\n * @param typ - The type.\n * @param mayHasJunk - Whether there may be junk.\n */\n private async recvBinary (typ: string, mayHasJunk: boolean = false): Promise<Uint8Array> {\n const buf = await this.recvCheck(typ, mayHasJunk)\n return decodeBuffer(buf)\n }\n\n /**\n * Check binary data.\n * @param expect - The expected buffer.\n */\n private async checkBinary (expect: Uint8Array): Promise<void> {\n const result = await this.recvBinary('SUCC')\n if (result.length !== expect.length) {\n throw new TrzszError(\n `Binary length check [${result.length}] <> [${expect.length}]`,\n null,\n true\n )\n }\n for (let i = 0; i < result.length; i++) {\n if (result[i] !== expect[i]) {\n throw new TrzszError(`Binary check [${result[i]}] <> [${expect[i]}]`, null, true)\n }\n }\n }\n\n /**\n * Send data.\n * @param data - The data.\n * @param binary - Whether to use binary mode.\n * @param escapeCodes - The escape codes.\n */\n private async sendData (\n data: Uint8Array,\n binary: boolean,\n escapeCodes: number[][]\n ): Promise<void> {\n if (!binary) {\n await this.sendBinary('DATA', data)\n return\n }\n\n const buf = escapeData(data, escapeCodes)\n this.writer(`#DATA:${buf.length}\\n`)\n this.writer(buf)\n }\n\n /**\n * Receive data.\n * @param binary - Whether to use binary mode.\n * @param escapeCodes - The escape codes.\n * @param timeoutInMilliseconds - The timeout in milliseconds.\n */\n private async recvData (\n binary: boolean,\n escapeCodes: number[][],\n timeoutInMilliseconds: number\n ): Promise<Uint8Array> {\n return await Promise.race<Uint8Array>([\n new Promise<Uint8Array>((_resolve, reject) =>\n setTimeout(() => {\n this.cleanTimeoutInMilliseconds = 3000\n reject(new TrzszError('Receive data timeout'))\n }, timeoutInMilliseconds)\n ),\n (async () => {\n if (!binary) {\n return await this.recvBinary('DATA')\n }\n const size = await this.recvInteger('DATA')\n const data = await this.buffer.readBinary(size)\n return unescapeData(data, escapeCodes)\n })()\n ])\n }\n\n /**\n * Send action.\n * @param confirm - Whether to confirm.\n * @param remoteIsWindows - Whether the remote is Windows.\n */\n public async sendAction (confirm: boolean, remoteIsWindows: boolean): Promise<void> {\n const action: Record<string, unknown> = {\n lang: 'js',\n confirm,\n version: trzszVersion,\n support_dir: true\n }\n if (this.isWindowsShell || remoteIsWindows) {\n action.binary = false\n action.newline = '!\\n'\n }\n if (remoteIsWindows) {\n this.remoteIsWindows = true\n this.protocolNewline = '!\\n'\n }\n await this.sendString('ACT', JSON.stringify(action))\n }\n\n /**\n * Receive action.\n */\n public async recvAction (): Promise<Record<string, unknown>> {\n const buf = await this.recvString('ACT', true)\n const action = JSON.parse(buf)\n const newline = (action as Record<string, unknown>).newline as string | undefined\n if (typeof newline === 'string' && newline.length > 0) {\n this.protocolNewline = newline\n }\n return action\n }\n\n /**\n * Send config.\n * @param args - The config arguments.\n * @param escapeChars - The escape characters.\n * @param tmuxMode - The tmux mode.\n * @param tmuxPaneWidth - The tmux pane width.\n */\n public async sendConfig (\n args: Record<string, unknown>,\n escapeChars: string[][],\n tmuxMode: number,\n tmuxPaneWidth: number\n ): Promise<void> {\n const config: Record<string, unknown> = { lang: 'js' }\n if ((args).quiet === true) {\n config.quiet = true\n }\n if ((args).binary === true) {\n config.binary = true\n config.escape_chars = escapeChars\n }\n if ((args).directory === true) {\n config.directory = true\n }\n if (typeof (args).bufsize === 'number') {\n config.bufsize = (args).bufsize\n }\n if (typeof (args).timeout === 'number') {\n config.timeout = (args).timeout\n }\n if ((args).overwrite === true) {\n config.overwrite = true\n }\n if (tmuxMode === TmuxMode.TmuxNormalMode) {\n config.tmux_output_junk = true\n }\n if (tmuxPaneWidth > 0) {\n config.tmux_pane_width = tmuxPaneWidth\n }\n let jsonStr = JSON.stringify(config)\n jsonStr = jsonStr.replace(/[\\u007F-\\uFFFF]/g, function (chr) {\n return '\\\\u' + ('0000' + chr.charCodeAt(0).toString(16)).slice(-4)\n })\n this.transferConfig = config\n await this.sendString('CFG', jsonStr)\n }\n\n /**\n * Receive config.\n */\n public async recvConfig (): Promise<Record<string, unknown>> {\n const buf = await this.recvString('CFG', true)\n this.transferConfig = JSON.parse(buf)\n this.tmuxOutputJunk = this.transferConfig.tmux_output_junk === true\n return this.transferConfig\n }\n\n /**\n * Send client exit.\n * @param msg - The message.\n */\n public async clientExit (msg: string): Promise<void> {\n await this.sendString('EXIT', msg)\n }\n\n /**\n * Receive exit.\n */\n public async recvExit (): Promise<string> {\n return await this.recvString('EXIT')\n }\n\n /**\n * Delete created files.\n */\n private async deleteCreatedFiles (): Promise<string[]> {\n const deletedFiles: string[] = []\n for (const file of this.createdFiles) {\n const path = await file.deleteFile()\n if (typeof path === 'string' && path.length > 0) {\n deletedFiles.push(path)\n }\n }\n return deletedFiles\n }\n\n /**\n * Handle client error.\n * @param err - The error.\n */\n public async clientError (err: Error): Promise<void> {\n await this.cleanInput(this.cleanTimeoutInMilliseconds)\n\n const errMsg = TrzszError.getErrorMessage(err)\n let trace = true\n if (err instanceof TrzszError) {\n trace = err.isTraceBack()\n if (err.isRemoteExit()) {\n return\n }\n if (err.isRemoteFail()) {\n if (trace) {\n console.log(errMsg)\n }\n return\n }\n }\n\n await this.sendString(trace ? 'FAIL' : 'fail', errMsg)\n if (trace) {\n console.log(errMsg)\n }\n }\n\n /**\n * Handle server error.\n * @param err - The error.\n */\n public async serverError (err: Error): Promise<void> {\n await this.cleanInput(this.cleanTimeoutInMilliseconds)\n\n const errMsg = TrzszError.getErrorMessage(err)\n let trace = true\n if (err instanceof TrzszError) {\n if (err.isStopAndDelete()) {\n const deletedFiles = await this.deleteCreatedFiles()\n if (deletedFiles.length > 0) {\n await this.serverExit([err.message + ':'].concat(deletedFiles).join('\\r\\n- '))\n return\n }\n }\n trace = err.isTraceBack()\n if (err.isRemoteExit() || err.isRemoteFail()) {\n await this.serverExit(errMsg)\n return\n }\n }\n\n await this.sendString(trace ? 'FAIL' : 'fail', errMsg)\n await this.serverExit(errMsg)\n }\n\n /**\n * Server exit - to be implemented by subclass or user.\n * @param msg - The message.\n */\n public async serverExit (_msg: string): Promise<void> {\n // Base implementation does nothing\n // Subclasses or users should override this\n }\n\n /**\n * Send file number.\n * @param num - The number of files.\n * @param progressCallback - The progress callback.\n */\n private async sendFileNum (num: number, progressCallback: ProgressCallback | null): Promise<void> {\n await this.sendInteger('NUM', num)\n await this.checkInteger(num)\n if (progressCallback != null) {\n progressCallback.onNum(num)\n }\n }\n\n /**\n * Send file name.\n * @param file - The file reader.\n * @param directory - Whether it's a directory.\n * @param progressCallback - The progress callback.\n */\n private async sendFileName (\n file: TrzszFileReader,\n directory: boolean,\n progressCallback: ProgressCallback | null\n ): Promise<string> {\n const relPath = file.getRelPath()\n const fileName = relPath[relPath.length - 1]\n if (directory) {\n const jsonName = {\n path_id: file.getPathId(),\n path_name: relPath,\n is_dir: file.isDir()\n }\n await this.sendString('NAME', JSON.stringify(jsonName))\n } else {\n await this.sendString('NAME', fileName)\n }\n const remoteName = await this.recvString('SUCC')\n if (progressCallback != null) {\n progressCallback.onName(fileName)\n }\n return remoteName\n }\n\n /**\n * Send file size.\n * @param size - The file size.\n * @param progressCallback - The progress callback.\n */\n private async sendFileSize (\n size: number,\n progressCallback: ProgressCallback | null\n ): Promise<void> {\n await this.sendInteger('SIZE', size)\n await this.checkInteger(size)\n if (progressCallback != null) {\n progressCallback.onSize(size)\n }\n }\n\n /**\n * Send file data.\n * @param file - The file reader.\n * @param size - The file size.\n * @param binary - Whether to use binary mode.\n * @param escapeCodes - The escape codes.\n * @param maxBufSize - The maximum buffer size.\n * @param progressCallback - The progress callback.\n */\n private async sendFileData (\n file: TrzszFileReader,\n size: number,\n binary: boolean,\n escapeCodes: number[][],\n maxBufSize: number,\n progressCallback: ProgressCallback | null\n ): Promise<Uint8Array> {\n let step = 0\n if (progressCallback != null) {\n progressCallback.onStep(step)\n }\n let bufSize = 1024\n let buffer = new ArrayBuffer(bufSize)\n const md5 = new Md5()\n while (step < size) {\n const beginTime = Date.now()\n const data = await file.readFile(buffer)\n await this.sendData(data, binary, escapeCodes)\n md5.appendByteArray(data)\n await this.checkInteger(data.length)\n step += data.length\n if (progressCallback != null) {\n progressCallback.onStep(step)\n }\n const chunkTime = Date.now() - beginTime\n if (data.length === bufSize && chunkTime < 500 && bufSize < maxBufSize) {\n bufSize = Math.min(bufSize * 2, maxBufSize)\n buffer = new ArrayBuffer(bufSize)\n } else if (chunkTime >= 2000 && bufSize > 1024) {\n bufSize = 1024\n buffer = new ArrayBuffer(bufSize)\n }\n if (chunkTime > this.maxChunkTimeInMilliseconds) {\n this.maxChunkTimeInMilliseconds = chunkTime\n }\n }\n return new Uint8Array((md5.end(true) as Int32Array).buffer)\n }\n\n /**\n * Send file MD5.\n * @param digest - The MD5 digest.\n * @param progressCallback - The progress callback.\n */\n private async sendFileMD5 (\n digest: Uint8Array,\n progressCallback: ProgressCallback | null\n ): Promise<void> {\n await this.sendBinary('MD5', digest)\n await this.checkBinary(digest)\n if (progressCallback != null) {\n progressCallback.onDone()\n }\n }\n\n /**\n * Send files.\n * @param files - The file readers.\n * @param progressCallback - The progress callback.\n */\n public async sendFiles (\n files: TrzszFileReader[],\n progressCallback: ProgressCallback | null\n ): Promise<string[]> {\n this.openedFiles.push(...files)\n\n const binary = this.transferConfig.binary === true\n const directory = this.transferConfig.directory === true\n const bufsizeVal = this.transferConfig.bufsize as number | undefined\n const maxBufSize = typeof bufsizeVal === 'number' ? bufsizeVal : 10 * 1024 * 1024\n const escapeCodes = Array.isArray(this.transferConfig.escape_chars)\n ? escapeCharsToCodes(this.transferConfig.escape_chars as string[][])\n : []\n\n await this.sendFileNum(files.length, progressCallback)\n\n const remoteNames: string[] = []\n for (const file of files) {\n const remoteName = await this.sendFileName(file, directory, progressCallback)\n\n if (!remoteNames.includes(remoteName)) {\n remoteNames.push(remoteName)\n }\n\n if (file.isDir()) {\n continue\n }\n\n const size = file.getSize()\n await this.sendFileSize(size, progressCallback)\n\n const digest = await this.sendFileData(file, size, binary, escapeCodes, maxBufSize, progressCallback)\n file.closeFile()\n\n await this.sendFileMD5(digest, progressCallback)\n }\n\n return remoteNames\n }\n\n /**\n * Receive file number.\n * @param progressCallback - The progress callback.\n */\n private async recvFileNum (progressCallback: ProgressCallback | null): Promise<number> {\n const num = await this.recvInteger('NUM')\n await this.sendInteger('SUCC', num)\n if (progressCallback != null) {\n progressCallback.onNum(num)\n }\n return num\n }\n\n /**\n * Receive file name.\n * @param saveParam - The save parameter.\n * @param openSaveFile - The open save file function.\n * @param directory - Whether it's a directory.\n * @param overwrite - Whether to overwrite.\n * @param progressCallback - The progress callback.\n */\n private async recvFileName (\n saveParam: unknown,\n openSaveFile: OpenSaveFile,\n directory: boolean,\n overwrite: boolean,\n progressCallback: ProgressCallback | null\n ): Promise<TrzszFileWriter> {\n const fileName = await this.recvString('NAME')\n const file = await openSaveFile(saveParam, fileName, directory, overwrite)\n this.createdFiles.push(file)\n await this.sendString('SUCC', file.getLocalName())\n if (progressCallback != null) {\n progressCallback.onName(file.getFileName())\n }\n return file\n }\n\n /**\n * Receive file size.\n * @param progressCallback - The progress callback.\n */\n private async recvFileSize (progressCallback: ProgressCallback | null): Promise<number> {\n const fileSize = await this.recvInteger('SIZE')\n await this.sendInteger('SUCC', fileSize)\n if (progressCallback != null) {\n progressCallback.onSize(fileSize)\n }\n return fileSize\n }\n\n /**\n * Receive file data.\n * @param file - The file writer.\n * @param size - The file size.\n * @param binary - Whether to use binary mode.\n * @param escapeCodes - The escape codes.\n * @param timeoutInMilliseconds - The timeout in milliseconds.\n * @param progressCallback - The progress callback.\n */\n private async recvFileData (\n file: TrzszFileWriter,\n size: number,\n binary: boolean,\n escapeCodes: number[][],\n timeoutInMilliseconds: number,\n progressCallback: ProgressCallback | null\n ): Promise<Uint8Array> {\n let step = 0\n if (progressCallback != null) {\n progressCallback.onStep(step)\n }\n const md5 = new Md5()\n while (step < size) {\n const beginTime = Date.now()\n const data = await this.recvData(binary, escapeCodes, timeoutInMilliseconds)\n await file.writeFile(data)\n step += data.length\n if (progressCallback != null) {\n progressCallback.onStep(step)\n }\n await this.sendInteger('SUCC', data.length)\n md5.appendByteArray(data)\n const chunkTime = Date.now() - beginTime\n if (chunkTime > this.maxChunkTimeInMilliseconds) {\n this.maxChunkTimeInMilliseconds = chunkTime\n }\n }\n return new Uint8Array((md5.end(true) as Int32Array).buffer)\n }\n\n /**\n * Receive file MD5.\n * @param digest - The MD5 digest.\n * @param progressCallback - The progress callback.\n */\n private async recvFileMD5 (\n digest: Uint8Array,\n progressCallback: ProgressCallback | null\n ): Promise<void> {\n const expectDigest = await this.recvBinary('MD5')\n if (digest.length !== expectDigest.length) {\n throw new TrzszError('Check MD5 failed')\n }\n for (let j = 0; j < digest.length; j++) {\n if (digest[j] !== expectDigest[j]) {\n throw new TrzszError('Check MD5 failed')\n }\n }\n await this.sendBinary('SUCC', digest)\n if (progressCallback != null) {\n progressCallback.onDone()\n }\n }\n\n /**\n * Receive files.\n * @param saveParam - The save parameter.\n * @param openSaveFile - The open save file function.\n * @param progressCallback - The progress callback.\n */\n public async recvFiles (\n saveParam: unknown,\n openSaveFile: OpenSaveFile,\n progressCallback: ProgressCallback | null\n ): Promise<string[]> {\n const binary = this.transferConfig.binary === true\n const directory = this.transferConfig.directory === true\n const overwrite = this.transferConfig.overwrite === true\n const timeoutVal = this.transferConfig.timeout as number | undefined\n const timeoutInMilliseconds = typeof timeoutVal === 'number' ? timeoutVal * 1000 : 100000\n const escapeCodes = Array.isArray(this.transferConfig.escape_chars)\n ? escapeCharsToCodes(this.transferConfig.escape_chars as string[][])\n : []\n\n const num = await this.recvFileNum(progressCallback)\n\n const localNames: string[] = []\n for (let i = 0; i < num; i++) {\n const file = await this.recvFileName(\n saveParam,\n openSaveFile,\n directory,\n overwrite,\n progressCallback\n )\n\n if (!localNames.includes(file.getLocalName())) {\n localNames.push(file.getLocalName())\n }\n\n if (file.isDir()) {\n continue\n }\n\n this.openedFiles.push(file)\n\n const size = await this.recvFileSize(progressCallback)\n\n const digest = await this.recvFileData(\n file,\n size,\n binary,\n escapeCodes,\n timeoutInMilliseconds,\n progressCallback\n )\n file.closeFile()\n\n await this.recvFileMD5(digest, progressCallback)\n }\n\n return localNames\n }\n}\n"],"names":["line","idx"],"mappings":";;;;AA6BO,MAAM,cAAc;AAAA;AAAA;AAAA;AAAA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ong
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/package.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "trzsz2",
3
+ "version": "1.0.0",
4
+ "description": "A pure JavaScript/TypeScript implementation of trzsz protocol - file transfer similar to zmodem but more simple and efficient",
5
+ "keywords": [
6
+ "trzsz",
7
+ "file transfer",
8
+ "protocol",
9
+ "terminal",
10
+ "zmodem",
11
+ "rz",
12
+ "sz",
13
+ "upload",
14
+ "download"
15
+ ],
16
+ "homepage": "https://github.com/zxdong262/trzsz2#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/zxdong262/trzsz2/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/zxdong262/trzsz2.git"
23
+ },
24
+ "license": "MIT",
25
+ "author": "ZHAO Xudong <zxdong262@gmail.com>",
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "import": {
30
+ "types": "./dist/esm/index.d.ts",
31
+ "default": "./dist/esm/index.js"
32
+ },
33
+ "require": {
34
+ "types": "./dist/cjs/index.d.ts",
35
+ "default": "./dist/cjs/index.cjs"
36
+ }
37
+ },
38
+ "./cjs-full": {
39
+ "require": {
40
+ "types": "./dist/cjs-full/index.d.ts",
41
+ "default": "./dist/cjs-full/index.cjs"
42
+ }
43
+ },
44
+ "./browser": {
45
+ "types": "./dist/browser/index.d.ts",
46
+ "default": "./dist/browser/trzsz2.js"
47
+ }
48
+ },
49
+ "main": "./dist/cjs/index.cjs",
50
+ "module": "./dist/esm/index.js",
51
+ "types": "./dist/esm/index.d.ts",
52
+ "browser": "./dist/browser/trzsz2.js",
53
+ "files": [
54
+ "dist",
55
+ "README.md",
56
+ "README.cn.md",
57
+ "LICENSE"
58
+ ],
59
+ "directories": {
60
+ "test": "test"
61
+ },
62
+ "scripts": {
63
+ "build": "node build/build-vite.mjs",
64
+ "build:esm": "vite build --config build/vite.config.esm.ts",
65
+ "build:cjs": "vite build --config build/vite.config.cjs.ts",
66
+ "build:cjs-full": "vite build --config build/vite.config.cjs-full.ts",
67
+ "build:browser": "vite build --config build/vite.config.browser.ts",
68
+ "prepublishOnly": "npm run build",
69
+ "test": "vitest run test/unit",
70
+ "test:watch": "vitest",
71
+ "test:upload": "node test/integration/trzsz-upload.test.mjs",
72
+ "test:download": "node test/integration/trzsz-download.test.mjs",
73
+ "lint": "ts-standard --project tsconfig.eslint.json && standard test/**/*.js",
74
+ "fix": "ts-standard --fix --project tsconfig.eslint.json"
75
+ },
76
+ "dependencies": {
77
+ "pako": "^2.1.0",
78
+ "ts-md5": "^1.3.1"
79
+ },
80
+ "devDependencies": {
81
+ "@types/node": "^20.10.0",
82
+ "@types/pako": "^2.0.4",
83
+ "ajv": "^8.18.0",
84
+ "esbuild": "^0.19.12",
85
+ "jsdom": "^28.1.0",
86
+ "ssh2": "^1.17.0",
87
+ "standard": "^17.1.0",
88
+ "ts-standard": "^12.0.2",
89
+ "typescript": "^5.3.0",
90
+ "vite": "^5.0.0",
91
+ "vite-plugin-dts": "^4.5.4",
92
+ "vitest": "^1.0.0"
93
+ },
94
+ "engines": {
95
+ "node": ">=18.0.0"
96
+ },
97
+ "standard": {
98
+ "env": [
99
+ "browser"
100
+ ],
101
+ "globals": [
102
+ "WebSocket",
103
+ "FileReader",
104
+ "atob",
105
+ "btoa"
106
+ ]
107
+ }
108
+ }