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

Support compression and decompression in JavaScript API #3153

Closed
bjorn opened this issue Oct 6, 2021 · 3 comments · Fixed by #3593
Closed

Support compression and decompression in JavaScript API #3153

bjorn opened this issue Oct 6, 2021 · 3 comments · Fixed by #3593
Assignees
Labels
feature It's a feature, not a bug.
Projects
Milestone

Comments

@bjorn
Copy link
Member

bjorn commented Oct 6, 2021

Something like tiled.compress and tiled.decompress, to make it easier to support zlib, gzip or zstd compression in JS extensions.

See mapeditor/tiled-extensions#11.

@bjorn bjorn added the feature It's a feature, not a bug. label Oct 6, 2021
@eishiya
Copy link
Contributor

eishiya commented Feb 28, 2023

Bumping for interest.

I recently wrote a custom map format that lets me define "sprites" made out of multiple tiles that my game can then use similarly to regular sprites, and it stores the layer data similarly to Tiled's map JSON format. It would be nice to support the same compression options without including bulky libraries in the script. For now, I can only conveniently support "csv" (native JSON array) and uncompressed base64 encoding.

Edit: I wonder what the argument and output types should be. For use with Qt.btoa, it would have to be a string, but those not using Qt.btoa and Qt.atob might prefer ArrayBuffers, for easier use with BinaryFile.

@eishiya
Copy link
Contributor

eishiya commented Mar 1, 2023

After spending some quality time with Qt's base64 encoder Qt.btoa(), I've realised it's either bugged or their approach is fundamentally broken: it works on UTF-8 strings that cannot accurately represent binary data: https://bugreports.qt.io/browse/QTBUG-71511

Because of this, I think Tiled should provide its own base64 encode/decode methods that can work with binary data (using e.g. ArrayBuffer), and Tiled's compress/decompress should probably also not use strings, to avoid encoding issues with JavaScript strings.

Edit: Apparently even the Qt devs recommend exposing one's own C++ functions for base64 encoding binary data, see the comments at the bottom here: https://codereview.qt-project.org/c/qt/qtdeclarative/+/244268

@bjorn bjorn added this to the Tiled 1.10 milestone Mar 1, 2023
@bjorn bjorn self-assigned this Mar 1, 2023
bjorn added a commit to bjorn/tiled-dev that referenced this issue Mar 1, 2023
Providing some convenience functions for commonly used compression
formats and base64 encoding, mostly useful when implementing file
formats.

Closes mapeditor#3153
@bjorn
Copy link
Member Author

bjorn commented Mar 1, 2023

After spending some quality time with Qt's base64 encoder Qt.btoa(), I've realised it's either bugged or their approach is fundamentally broken: it works on UTF-8 strings that cannot accurately represent binary data: https://bugreports.qt.io/browse/QTBUG-71511

That's rather surprising and quite unfortunate. Hopefully the new tiled.toBase64 and tiled.fromBase64 added by #3593 will work better.

bjorn added a commit that referenced this issue Mar 1, 2023
…/decoding (#3593)

Providing some convenience functions for commonly used compression
formats and Base64 encoding, mostly useful when implementing file
formats.

Closes #3153
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature It's a feature, not a bug.
Projects
Status: Done
Roadmap
  
Awaiting triage
Development

Successfully merging a pull request may close this issue.

2 participants