fgasper / zmodemjs Goto Github PK
View Code? Open in Web Editor NEWzmodem.js - ZMODEM in JavaScript
License: Apache License 2.0
zmodem.js - ZMODEM in JavaScript
License: Apache License 2.0
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.
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.
Cannot read property ‘Sentry’ of undefined
_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.
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?
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
What happens when you follow README.md’s TROUBLESHOOTING steps?
To Reproduce
Steps to reproduce the behavior:
import 'zmodem.js/dist/zmodem.devel'
import * as zmodemAddOn from 'xterm/dist/addons/zmodem/zmodem'
// ....
Terminal.applyAddon(zmodemAddOn)
// onOpen
() => {
this.xterm.zmodemAttach(this.webSocket, {
noTerminalWriteOutsideSession: true,
})
}
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)
}
Expected behavior
download success
Environment(s):
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?
I will compare the code later to see what happens.
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
Ubuntu 18.04.3 LTS
lrzsz version 0.12.21rc
When running rz
When running sz
This problem has troubled me for a long time
Thanks again
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)
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.
if there is a demo?
I'd love to include a "native" Z-Modem in ENiGMA 1/2 BBS - is this ready for general-ish use?
Can you provide some demos about zmodemjs?
how to use in VUe
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.
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~!~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.