Making webshell and terminal supports trzsz ( trz / tsz ), which similar to rz / sz, and compatible with tmux.

Overview

trzsz.js

Making webshell and terminal supports trzsz ( trz / tsz ), which similar to ( rz / sz ), and compatible with tmux.

MIT License npmjs trzsz

Why?

Considering laptop -> hostA -> hostB -> docker -> tmux, using scp or sftp is inconvenience.

In this case, lrzsz ( rz / sz ) is convenient to use, but unfortunately it's not compatible with tmux.

tmux is not going to support rz / sz ( 906, 1439 ), and creating a new tools is much easier than patching tmux.

trzsz.js is a js version of trzsz, which supports webshell running in browser, terminal built with electron, etc.

Getting Started

  • Install the module

    npm install trzsz
    

    or

    yarn add trzsz
    
  • Use in Node.js

    import { TrzszFilter } from "trzsz";

    or

    const { TrzszFilter } = require("trzsz");
  • Use in browser

    <script src="node_modules/trzsz/lib/trzsz.js"></script>
  • Create TrzszFilter object

    const trzszFilter = new TrzszFilter({
      // The trzsz options, see below
    });
  • Generally, the output of the server is forwarded to the terminal. Pass the output through TrzszFilter.

    const trzszFilter = new TrzszFilter({
      // The output will be forwarded back by TrzszFilter, unless the user runs ( trz / tsz ) on the server.
      writeToTerminal: (data) => terminal.write(typeof data === "string" ? data : new Uint8Array(data)),
    });
    
    // forward the output to TrzszFilter
    webSocket.addEventListener("message", (ev) => trzszFilter.processServerOutput(ev.data));
  • Generally, the user input is forwarded to the server. Pass the user input through TrzszFilter.

    const trzszFilter = new TrzszFilter({
      // The user input will be forwarded back by TrzszFilter, unless there are files being transferred.
      sendToServer: (data) => webSocket.send(data),
    });
    
    // forward the user input to TrzszFilter
    terminal.onData((data) => trzszFilter.processTerminalInput(data));
    // forward binary input to TrzszFilter
    terminal.onBinary((data) => trzszFilter.processBinaryInput(data));
  • Let TrzszFilter know the terminal columns for rendering progress bar.

    const trzszFilter = new TrzszFilter({
      // initialize the terminal columns
      terminalColumns: terminal.cols,
    });
    
    // reset the terminal columns
    terminal.onResize((size) => trzszFilter.setTerminalColumns(size.cols));
  • If running in Node.js and TrzszFilter can require('fs'), chooseSendFiles and chooseSaveDirectory are required. If running in web browser, they will be ignored. Note that they are async functions.

    const trzszFilter = new TrzszFilter({
      // call on the user runs trz ( upload files ) on the server and no error on require('fs').
      chooseSendFiles: async () => {
        // return `undefined` if the user cancels.
        // return an array of file paths choosed by the user.
        return ["/path/to/file1", "/path/to/file2"];
      },
      // call on the user runs tsz ( download files ) on the server and no error on require('fs').
      chooseSaveDirectory: async () => {
        // return `undefined` if the user cancels.
        // return a directory path choosed by the user.
        return "/path/to/directory";
      },
    });
  • TrzszAddon is a wrapper for TrzszFilter. If you are using xterm-addon-attach, just replace AttachAddon with TrzszAddon.

    import { Terminal } from 'xterm';
    import { TrzszAddon } from 'trzsz';
    
    const terminal = new Terminal();
    const trzszAddon = new TrzszAddon(webSocket);
    terminal.loadAddon(trzszAddon);

Examples

Screenshot

upload and download files in web browser

browser example

upload and download files in electron app

electron example

Contact

Feel free to email me [email protected].

You might also like...

A full-stack application that allows gamers to connect and match to people with similar interests.

A full-stack application that allows gamers to connect and match to people with similar interests.

Platform that allows gamers to connect and find people with similar interests. Built during the @Rocketseat NLW eSports event. Preview: Quickstart Ser

Oct 2, 2022

An in-browser JavaScript variable dumper, similar in functionality to ColdFusion's cfdump tag.

prettyPrint.js © James Padolsey prettyPrint.js is an in-browser JavaScript variable dumper, similar in functionality to ColdFusion's cfdump tag. First

Sep 18, 2022

lua-pack is an advanced lua bundler similar to webpack made for lua 5.1+ written in js

lua-pack is an advanced lua bundler similar to webpack made for lua 5.1+ written in js that makes working on large scale projects easy and fast. it takes all the files in your project and packs them into a single production ready file.

May 14, 2022

Colr Pickr, a vanilla JavaScript color picker component built with SVGs, with features like saving colors. Similar design to the chrome-dev-tools color picker.

Colr Pickr, a vanilla JavaScript color picker component built with SVGs, with features like saving colors. Similar design to the chrome-dev-tools color picker.

Colr Pickr Colr Pickr, a vanilla JavaScript color picking component built with SVGs, with features like saving colors. Similar design to the chrome-de

Jun 27, 2022

A progressive image loading library. Inspired by Medium’s similar technique.

A progressive image loading library. Inspired by Medium’s similar technique.

Blurry Image Load Synopsis A lightweight, zero-dependency library that loads images on demand. Until the images are loaded, a very small version of ea

Dec 10, 2022

A soundboard app similar to Voicemod, but free!

A soundboard app similar to Voicemod, but free!

SoundboardApp A soundboard app similar to Voicemod, but free - created as a project to learn ElectronJS and NodeJS with. Features The interface is qui

Aug 7, 2022

jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).

jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).

evol-colorpicker · evol-colorpicker is a web color picker which looks like the one in Microsoft Office 2010. It can be used inline or as a popup bound

Dec 14, 2022

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

Mar 1, 2021

Simple string diffing. Given two strings, striff will return an object noting which characters were added or removed, and at which indices

Simple string diffing. Given two strings, striff will return an object noting which characters were added or removed, and at which indices

Jan 6, 2023
Comments
  • try/catch is invalid

    try/catch is invalid

    https://github.com/trzsz/trzsz.js/blob/7681a63a4cafa460949bec253f277466f9ee5d52/src/filter.ts#L190

    My environment is browser but it goes to nodejs code

    image

    opened by fullee 5
  • node12 is not supported?

    node12 is not supported?

    I use npm install trzsz to install. it will report the error.

    $ npm install trzsz
    npm WARN saveError ENOENT: no such file or directory, open '/home/harriszh/package.json'
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN enoent ENOENT: no such file or directory, open '/home/harriszh/package.json'
    npm WARN harriszh No description
    npm WARN harriszh No repository field.
    npm WARN harriszh No README data
    npm WARN harriszh No license field.
    
    + [email protected]
    added 1 package from 1 contributor and audited 1 package in 2.149s
    found 0 vulnerabilities
    
    opened by zhuzhzh 3
  • chooseSaveDirectory is not a function

    chooseSaveDirectory is not a function

    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/site-packages/trzsz/svr/send.py", line 73, in main
        action = recv_action()
      File "/usr/local/lib/python3.6/site-packages/trzsz/libs/utils.py", line 318, in recv_action
        return recv_json('ACT')
      File "/usr/local/lib/python3.6/site-packages/trzsz/libs/utils.py", line 307, in recv_json
        dic = recv_string(typ, may_has_junk)
      File "/usr/local/lib/python3.6/site-packages/trzsz/libs/utils.py", line 233, in recv_string
        return decode_buffer(recv_check(typ, may_has_junk)).decode('utf8')
      File "/usr/local/lib/python3.6/site-packages/trzsz/libs/utils.py", line 213, in recv_check
        raise TrzszError(buf, typ)
    trzsz.libs.utils.TrzszError: TypeError: this.chooseSaveDirectory is not a function
        at t2.<anonymous> (http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:2655:29)
        at http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:109:21
        at Object.next (http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:118:8)
        at http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:55:38
        at new Promise (<anonymous>)
        at e (http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:34:10)
        at t2.handleTrzszDownloadFiles (http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:2648:12)
        at t2.<anonymous> (http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:2621:131)
        at http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:109:21
        at Object.next (http://localhost:3000/node_modules/.vite/deps/trzsz.js?v=a7c740da:118:8)
    
    opened by fullee 3
  • [feature request] Support rz/sz

    [feature request] Support rz/sz

    Currently I use https://github.com/FGasper/zmodemjs, which have some issues when transfer big files, wondering if this project could provide support for rz/sz, so it can be used as a replacement to zmodemjs.

    opened by zxdong262 1
Releases(v1.0.0)
A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, making it easy and fast.

RESPRESS A RESP 'Redis Serialization Protocol' library implementation to generate a server, uses a similar approach to express to define you serer, ma

Yousef Wadi 9 Aug 29, 2022
A Multichain crypto wallet library that supports Ethereum, Solana and other EVM compatible blockchains.

Multichain Crypto Wallet A Multichain crypto wallet library that supports Ethereum, Solana and other EVM compatible blockchains. Installation npm inst

Abdulfatai Suleiman 117 Jan 2, 2023
A simple cmatrix-like terminal decoration written in JavaScript that supports window resizing.

jsmatrix A simple cmatrix-like terminal decoration written in JavaScript that supports window resizing. Getting Started Dependencies NodeJS Any termin

Fülöp Tibor 7 Mar 27, 2022
zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

Marto.eth 10 Aug 25, 2022
chain-syncer is a module which allows you to synchronize your app with any ethereum-compatible blockchain/contract state. Fast. Realtime. Reliable.

Chain Syncer Chain Syncer is a JS module which allows you to synchronize your app with any ethereum-compatible blockchain/contract state. Fast. Realti

Miroslaw Shpak 10 Dec 15, 2022
AdsPower supports Local API, which has functions like reading and writing account configuration information, opening and closing browsers, searching for accounts.

AdsPower supports Local API, which has functions like reading and writing account configuration information, opening and closing browsers, searching for accounts. Besides, it can cooperate with Selenium and Puppeteer to execute browser operations automatically.

AdsPower Official 20 Dec 1, 2022
This package generates a unique ID/String for different browsers. Like chrome, Firefox and any other browsers which supports canvas and audio Fingerprinting.

Broprint.js The world's easiest, smallest and powerful visitor identifier for browsers. This package generates a unique ID/String for different browse

Rajesh Royal 68 Dec 25, 2022
Qwerty is the first social website focused on connecting students with similar classes and gender identities

?? Qwerty ?? Qwerty is the first social website focused on connecting students with similar classes and gender identities. To get started simply input

Benson Liu 3 Oct 21, 2022
pre-calculated list of similar Persian words ordered by rating and best match

similar-persian-words pre-calculated list of similar Persian words ordered by rating and best match. Install npm: npm install similar-persian-words Us

peyman farahmand 6 May 29, 2022
A fast, safe and easy caching mechanism similar to Redis written in typescript

Viper Viper is a memory based caching mechanism which is aimed towards ease of use and speed. It's in a very early stage right now and not meant to us

Japroz Saini 1 Jan 24, 2022