GithubHelp home page GithubHelp logo

fgasper / zmodemjs Goto Github PK

View Code? Open in Web Editor NEW
128.0 5.0 24.0 676 KB

zmodem.js - ZMODEM in JavaScript

License: Apache License 2.0

JavaScript 97.65% Perl 2.35%
zmodem javascript shell terminal xmodem ymodem websocket

zmodemjs's Issues

Not receiving `OO` causes session to get stuck

It seems like a relatively common problem that the terminating OO from sz gets lost or misparsed or something. See all these issues:
sorenisanerd/gotty#46
tsl0922/ttyd#239
tsl0922/ttyd#279
Eugeny/tabby#6259
cferdinandi/tabby#132
Eugeny/tabby#5196
trzsz/tabby-trzsz#2
Eugeny/tabby#5132

This lets me call .allow_missing_OO(true) on the session object which SEEMS to make the problem go away:

diff --git a/src/zsession.js b/src/zsession.js
index 5f0b8f9..cafe57f 100644
--- a/src/zsession.js
+++ b/src/zsession.js
@@ -193,6 +193,10 @@ Zmodem.Session = class ZmodemSession extends _Eventer {
         //console.warn("Invalid first Zmodem header", hdr);
     }
 
+    allow_missing_OO(flag) {
+        this._allow_missing_OO = !!flag;
+    }
+
     /**
      * Sets the sender function that a Session object will use.
      *
@@ -549,7 +553,7 @@ Zmodem.Session.Receive = class ZmodemReceiveSession extends Zmodem.Session {
             if (this._input_buffer.length < 2) return;
 
             //if it’s OO, then set this._bytes_after_OO
-            if (Zmodem.ZMLIB.find_subarray(this._input_buffer, OVER_AND_OUT) === 0) {
+            if (this._allow_missing_OO || Zmodem.ZMLIB.find_subarray(this._input_buffer, OVER_AND_OUT) === 0) {
 
                 //This doubles as an indication that the session has ended.
                 //We need to set this right away so that handlers like

...but I can't reliably trigger the problem, so my confidence in this approach is not great.

Do you have thoughts on how to address this? The spec suggests that if the OO does not arrive, you should just move on with your life after a brief timeout, so maybe we just need to implement that timeout? Just getting stuck in this state doesn't benefit anyone.

How do I exit upload or download on the zmodemjs

Describe the bug

I try socket.send(str2ab('\x18\x18\x18\x18\x18\x08\x08\x08\x08\x08')) but error occur. I don't know why and how to use cancel correctly.

Thank you.

image

image

Environment(s):

  • JS engine
    Google Chrome v101.0.4951.64

Additional context
Add any other context about the problem here.

xterm.js v4 and zmodem.js

@FGasper

Imho zmodem was a valuable addon for xterm.js, but got removed with v4 due changes on our side. Do you have any plans to reestablish such an addon?

Just want to let you know that I might do an addon myself in case you dont want to maintain it yourself.

Uncaught TypeError: Cannot read property 'ZRPOS' of null

_Uncaught TypeError: Cannot read property 'ZRPOS' of null
at r.Session.Send._consume_header (VM72 zmodem.js:1)
at r.Session.Send._parse_and_consume_header (VM72 zmodem.js:1)
at r.Session.Send.consume_first (VM72 zmodem.js:1)
at r.Session.Send.consume (VM72 zmodem.js:1)
at t.Sentry.consume (VM72 zmodem.js:1)
at WebSocket.handleWSMessage (VM73 zmodem.js:30)

When I use 'rz' to upload a file,I got this.
So what`s the probrom.

'Zmodem.Browser' is Undefined

When I tried to use zmodem.js in Vue Cli, I found this problem after writing according to your document. Then I went to look at the source code of zmodem.js/src/zessions.js in node_modules and found that you did not introduce'zmodem_browser.js'. I wonder if you did it intentionally?

  • zmodem.js 0.1.10version

Unhandled header!

Describe the bug
I use zmodemjs in xterm.js which version in 3.14.5, when enter sz, console get error: Uncaught Error: Unhandled header: ZRQINIT
image

What happens when you follow README.md’s TROUBLESHOOTING steps?

  1. when i create an empty file and use sz to download, console get error.
  2. Transfer a small file, get same error.
  3. Transfer a file that contains all possible octets, get same error.

To Reproduce
Steps to reproduce the behavior:

  1. apply plugin
import 'zmodem.js/dist/zmodem.devel'
import * as zmodemAddOn from 'xterm/dist/addons/zmodem/zmodem'
// ....
Terminal.applyAddon(zmodemAddOn)
  1. attach zmode after websocket connected
// onOpen
() => {
    this.xterm.zmodemAttach(this.webSocket, {
        noTerminalWriteOutsideSession: true,
    })
}
  1. listen zmodemDetect after terminal inited
this.xterm.on('zmodemDetect', (detection) => {
    try {
        this.xterm.detach()
    } catch (e) {
        console.error(e)
    }

    const zsession = detection.confirm()

    let promise
    if (zsession.type === 'receive') {
        promise = this.downloadFile(zsession)
    } else {
        promise = this.uploadFile(zsession)
    }

     promise
        .then(() => {
            try {
                term.detach()
            } catch (e) {
              console.error(e);
            }

           try {
                term.attach(this.webSocket)
            } catch (e) {
              console.error(e);
            }
        })
        .catch((err: Error) => {
            console.error(err)
        })
})

// download function
downloadFile = (zsession: any) => {
  const self = this
  zsession.on('offer', (xfer: any) => {
    function on_form_submit() {
      const FILE_BUFFER: any[] = []
      xfer.on('input', (payload: any) => {
        self.updateProgress(xfer)
        FILE_BUFFER.push(new Uint8Array(payload))
      })

      xfer
        .accept()
        .then(() => {
          self.saveFile(xfer, FILE_BUFFER)
          this.xterm.write('\r\n')
        })
        .catch((err: Error) => {
          console.error(err)
        })
    }

    on_form_submit()
  })

  const promise = new Promise((res) => {
    zsession.on('session_end', () => {
      console.log('-----zession close----')
      res('')
    })
  })

  zsession.start()
  return promise
}

// save file function
saveFile = (xfer, buffer) => {
    return Zmodem.Browser.save_to_disk(buffer, xfer.get_details().name)
}
  1. enter sz empty.bin
  2. See error

Expected behavior
download success

Screenshots
image
image
image

Environment(s):

  • OS: MacOS
  • JS engine : Chrome

Additional context
I found the same problem in issues, but I can't find the solution.

I understand that may not be a bug, maybe it's my usage problem, but i have no idea if this is a back-end problem or a front-end problem.

I though this is a back-end problem because the header order is wrong, but my companion told me, he can download file with terminal app from the same machine.

My code is copy from gowebssh, and i check it for many time, but I still can't solve this problem. So, can you give me some suggestions?

Unhandled header!

I try to implement zmodem protocol using zmodemjs on websocket
And follow the zmodemjs documentation
But when I input rz and sz commands, I get an error. I do n’t know how to solve it.
Can you give me some suggestions or solutions?
Thank you

Platform and software version

Ubuntu 18.04.3 LTS
lrzsz version 0.12.21rc

Console error output

When running rz
image
When running sz
image

This problem has troubled me for a long time
Thanks again

uglifyjs: SyntaxError: Unexpected token: name (ZmodemError)

I'm not sure whether this is a uglifyjs or zmodemjs issue, reproduce command:

./node_modules/.bin/uglifyjs node_modules/zmodem.js/dist/zmodem.devel.js                                                                           
Parse error at node_modules/zmodem.js/dist/zmodem.devel.js:213,21
SyntaxError: Unexpected token: name (ZmodemError)
Error
    at new JS_Parse_Error (eval at <anonymous> (.../ttyd/html/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1545:18)

No progress report on sending

Zmodem.Browser.send_files allows you to pass an on_progress handler. Sadly, it isn't actually usable for a couple of reasons.

First of all, it seems Chrome (and possibly others, I haven't checked) only triggers the progress handler when it's done loading the file. I've tried with files up to ~25 MB in size. Honestly, this makes sense, since on any modern system, loading a file into memory is very fast.

Second, I'm not very interested in learning about the progress in loading the file. I'm much more interested in learning about the progress in sending the file. However, the end_files routine sends as much data as it has available without splitting it into smaller chunks. Due to the first problem, this means the whole file gets sent in one go and my first progress event is when it's done.

I propose adding a chunkSize option to send_files. Files will get split into chunks of up to chunkSize and the on_progress handler should get triggered for each chunk sent.

Vue

how to use in VUe

Uncaught RangeError: Maximum call stack size exceeded

I'm debugging my server side C code, this happens when I changed the server code to send all the buffered data at once.

Uncaught RangeError: Maximum call stack size exceeded
    at ZmodemReceiveSession._strip_and_enqueue_input ((index):9501)
    at ZmodemReceiveSession.consume ((index):9292)
    at ZmodemSentry.consume ((index):8900)
    at WebSocket.ws.onmessage ((index):339)

Chrome Network Tab shows the maximum websocket message size is 327751.

when sz in linux, crc32 failed

exception:

Uncaught Error: CRC check failed! (got: 97,49,55,32; expected: 99,203,3,169)
    at a (zmodem.js:1)
    at Object.verify32 (zmodem.js:1)
    at i (zmodem.js:1)
    at Function.parse (zmodem.js:1)
    at r.Session.Receive._parse_and_consume_header (zmodem.js:1)
    at r.Session.Receive._consume_first (zmodem.js:1)
    at r.Session.Receive.consume (zmodem.js:1)
    at t.Sentry.consume (zmodem.js:1)
    at WebSocket.handleWSMessage (zmodem.ts:75)

lrzsz version:

sz (lrzsz) 0.12.21rc

but use sz -e is ok

sz -h
-e, --escape                escape all control characters (Z)

so, i think when your crc, include control charaters?

can you fix it.
Thank you~!~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.