mirror of
https://github.com/appy-one/acebase-client.git
synced 2026-05-24 22:01:18 -06:00
[GH-ISSUE #25] issue read/writing binary data #18
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/acebase-client#18
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @donl on GitHub (Sep 6, 2022).
Original GitHub issue: https://github.com/appy-one/acebase-client/issues/25
Originally assigned to: @appy-one on GitHub.
Using regular AceBase seems fine, however in a client/server setup there appears to be an issue with binary data.
Here is an example that hopefully illustrates the issue:
@appy-one commented on GitHub (Sep 6, 2022):
Hi Don,
I'm trying to run your code snippet, but I get a
TypeError: Cannot read properties of undefined (reading 'digest')on the lineconst hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer);Also, I had to install and import
node-fetchto get thefetchon the image to work.Can you edit the code snippet to isolate the exact issue?
@donl commented on GitHub (Sep 6, 2022):
I'm running node v18.7.0 -- it warns that Fetch is experimental but runs and I believe the crypto module is rather new in node as well. I had to specify
"type": "module"inpackage.jsonfor the import syntax.The gist of the problem is when trying to store binary data from a png for instance, the result ends up a handful of bytes larger with the bytes mismatching from the original after a certain (random?) offset it seems.
It has worked ok with data from a small textual svg file and even small png (<2000 bytes?) data.
I'll see if I can rework the example for you.
Thanks!
@donl commented on GitHub (Sep 6, 2022):
... the hashing was just an "easy" way to visually compare the binary data results. The
console.loglines with thehex()of the original binary data object would show the actual data.@appy-one commented on GitHub (Sep 6, 2022):
Thanks, I switched to Node 18.8.0 to test
@appy-one commented on GitHub (Sep 6, 2022):
It looks like the ascii85 encoding used for transport is causing an issue. I'll have to investigate this further.
@donl commented on GitHub (Sep 6, 2022):
Here is an updated snippet, includes a working example in the comments.
@donl commented on GitHub (Sep 7, 2022):
I just keep muddling my way through... It seems the crux of the issue is a missing
continuehere duringencode:Upon research, I stumbled upon the Z85 encoding (z85-codec). Interesting in that no escaping is necessary for json (eg
"). A quick test with a random jpeg had about .5% of the total space used due to escape characters. There might be some computation tradeoffs for and against to consider-- let alone backwards compatibility.While going down this rabbit hole it made me wonder about packing/squashing data into the high bits of the UTF16 encoding used by IndexedDB.
@appy-one commented on GitHub (Sep 8, 2022):
I think you nailed it with that
continue, I'll perform some more tests and release a new version@appy-one commented on GitHub (Sep 10, 2022):
I published acebase-client v1.17.1, which will fix this issue from the client side, server side is up next!
@appy-one commented on GitHub (Sep 10, 2022):
I just published scebase-server v1.13.0 which fixes this issue on the server side.
Thanks for your help @donl, really appreciated! 💯