Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip in data: uri #80

Merged
merged 2 commits into from
Jan 22, 2024
Merged

gzip in data: uri #80

merged 2 commits into from
Jan 22, 2024

Conversation

hrgdavor
Copy link
Owner

fixes: #76

here is a sample gzipped script:
data:application/gzip;base64,H4sICN1FqGUAA3Rlc3QADcrBDkAwDADQu6/YjV3GxUUi8SuLFRXrpl1FIv6dd34xBT3AwZ0TFxkXpblgIhM9UmMfhqJMhuFUZGjqaZfZhzamAAfSWluXGSMWvECc5A3+9LAPqDKYvnvtW33S8ZutYgAAAA==

for script:

module.exports=function main(){return require('@jscad/modeling').primitives.sphere({radius: 50})}

@Hermann-SW works temporarily here(you may need to hit ctrl+F5) until merged and published to jscad.app

https://3d.hrg.hr/jscad/app1/#data:application/gzip;base64,H4sICN1FqGUAA3Rlc3QADcrBDkAwDADQu6/YjV3GxUUi8SuLFRXrpl1FIv6dd34xBT3AwZ0TFxkXpblgIhM9UmMfhqJMhuFUZGjqaZfZhzamAAfSWluXGSMWvECc5A3+9LAPqDKYvnvtW33S8ZutYgAAAA==

@Hermann-SW
Copy link
Contributor

Hermann-SW commented Jan 18, 2024

@Hermann-SW works temporarily here(you may need to hit ctrl+F5) until merged and published to jscad.app

https://3d.hrg.hr/jscad/app1/#data:application/gzip;base64,H4sICN1FqGUAA3Rlc3QADcrBDkAwDADQu6/YjV3GxUUi8SuLFRXrpl1FIv6dd34xBT3AwZ0TFxkXpblgIhM9UmMfhqJMhuFUZGjqaZfZhzamAAfSWluXGSMWvECc5A3+9LAPqDKYvnvtW33S8ZutYgAAAA==

@hrgdavor Thank you, works nicely with bigger scripts, with this bash script:

pi@raspberrypi5:~/JSCAD $ cat doit2.b2 
#!/bin/bash
browser=firefox
browser=chromium-browser

$browser "3d.hrg.hr/jscad/app1/#data:application/gzip;base64,`gzip -c $1 | base64 -w 0`"
pi@raspberrypi5:~/JSCAD $ 

I started

./doit2.b2 C36_10.correct.jscad

with 23891 bytes length script. The complete URL length is only 6547 bytes!
6547 bytes length URL to test
(you might want to select 6coloring for face coloring, and set look_inside to yes and rotate the sphere for inside view)

Thanks to you and your colleagues for such quick resolutions and implementation of new feature!

@Hermann-SW
Copy link
Contributor

Hermann-SW commented Jan 21, 2024

@hrgdavor
Hi, the "6547 bytes length URL to test" link above does not work anymore.
Can you please reenable https://3d.hrg.hr/jscad/app1/#data:application/gzip;base64,... feature?

I need that to test whether that feature allows to extend the jscad.app URL length restriction.

I tested, and if base64 encoded data URL (without gzip) is >32KB, it does not work on jscad.app.
gzip+base64 should work for my new GP3D generated demo model, that is accessible as gist as well since last night:
https://jscad.app/#https://gist.githubusercontent.com/Hermann-SW/b3e85c8fe6827cd29238c14f9da346be/raw/C36.10.fixed.jscad.good_enough.jscad

@hrgdavor
Copy link
Owner Author

@Hermann-SW the PR is not yet merged nad the mentioned url is just experimental page use to share with ppl before it is available on jscad.app.

here is a link taht will live longer for that PR only,
https://3d.hrg.hr/jscad/app-gzip/#data:application/gzip;base64,H4sICN1FqGUAA3Rlc3QADcrBDkAwDADQu6/YjV3GxUUi8SuLFRXrpl1FIv6dd34xBT3AwZ0TFxkXpblgIhM9UmMfhqJMhuFUZGjqaZfZhzamAAfSWluXGSMWvECc5A3+9LAPqDKYvnvtW33S8ZutYgAAAA==

but after it is on official jscad.app it will ikely be removed to declutter my hosting folder

@Hermann-SW
Copy link
Contributor

Hermann-SW commented Jan 21, 2024

@hrgdavor
THANK you, I see that "app1" server became "app-gzip".
I updated the tool in my repo:
https://github.com/Hermann-SW/GP3D/blob/main/tools/view_gzb64
I will update again to jscad.app when it works there.

tools/view_b64 app-gzip.jscad fails because of 32KB URL restriction for my newest model.
But changed tool does work !

pi@raspberrypi5:~/GP3D $ tools/view_gzb64 app-gzip.jscad
Opening in existing browser session.
pi@raspberrypi5:~/GP3D $ 

You can open the 6655 bytes data url and see latest new features generated with PARI/GP script (look_inside enabled, theta angles as vertex labels, vertices not on seperating circle drawn as half spheres, 6coloring chosen as face coloring).

Copy link
Collaborator

@platypii platypii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work. My only comments would be:

  • I hate adding dependencies.
  • fflate looks very compact, and provides real value, cool
  • base64-arraybuffer seems unnecessary, as it could be done using native apis only.
  • these dependencies are not big so I don't it too be too much of a problem, but also I think it will be rare that people use this code path. Would it make sense to split out the gzip decoding as a bundle and only load it if needed?

I tested this alternative and it appears to work fine, without the base64-arraybuffer dependency:

/**
* Converts a Base64 encoded string to an ArrayBuffer.
* @param {string} base64 - base64 encoded string
* @returns {ArrayBuffer} output ArrayBuffer
*/
const base64ToArrayBuffer = (base64) => {
 return Uint8Array.from(atob(base64), c => c.charCodeAt(0)).buffer
}

@hrgdavor hrgdavor merged commit 7efa71e into main Jan 22, 2024
1 check passed
@hrgdavor
Copy link
Owner Author

@Hermann-SW
Copy link
Contributor

Hermann-SW commented Jan 22, 2024

@hrgdavor
https://stamm-wilbrandt.de/cgi-bin/echo-e.to.braille.pl?i=Thank+you+%21

$ echo -e 'Thank you !' | pbmtext -builtin fixed | pnmcrop | pbmtobraille
⡖⢲⠒⡎⡇⣀⠀⢀⣀⡀⢀⢀⣀⠀⢹⠀⣀⠀⠀⠀⠀⣀⡀⣀⡀⢀⣀⠀⣀⠀⣀⠀⠀⠀⠀⠀⢸
⠀⢸⠀⠀⡏⠀⡇⢠⠒⢺⠀⡏⠀⡇⢸⠪⡀⠀⠀⠀⠀⠘⣄⡜⠀⡇⠀⡇⢸⠀⢸⠀⠀⠀⠀⠀⠸
⠈⠉⠉⠈⠉⠈⠉⠀⠉⠁⠉⠉⠀⠉⠉⠀⠈⠁⠀⠀⠀⢀⡸⠀⠀⠈⠉⠀⠀⠉⠁⠁⠀⠀⠀⠀⠈
$ 

I just updated GP3D tool to target jscad.app now:
https://github.com/Hermann-SW/GP3D/blob/main/tools/view_gzb64

I created below link with that tool:

pi@raspberrypi5:~/GP3D $ tools/view_gzb64 gp.jscad
Opening in existing browser session.
pi@raspberrypi5:~/GP3D $

6552 bytes base64(gzip(jscad)) data URL — works like a charm ...
https://stamm-wilbrandt.de/images/JSCAD.half_vertex.png

@hrgdavor hrgdavor deleted the gzip-in-data-uri branch January 22, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support gzip in data: uri
3 participants