Mqx
Mqx2mo ago

Binary files in jsr package

Hey I am currently trying to understand the „new“ (for me) package format (jsr.json) for Deno packages and I was wandering how binary files are handled in such a package when using the package. For example if I have a DLL file for my ffi module can I just include it in the include statement inside the jsr.io file so that it gets cached when I use the package? Or do I need relay on a library like plug that downloads non ts/js files that I need?
8 Replies
jeff.hykin
jeff.hykin2mo ago
Idk about jsr, but if you want it to work with bundlers (and JSR) I made this tool a couple years ago for binary files. It let's you import anything as a Uint8Array. I used it to make deno-tree-sitter and also use it in a couple other of my deno modules https://github.com/jeff-hykin/binaryify/
GitHub
GitHub - jeff-hykin/binaryify: 💾 📦 ✅ bundling misc files into Java...
💾 📦 ✅ bundling misc files into Javascript. Contribute to jeff-hykin/binaryify development by creating an account on GitHub.
Mqx
Mqx2mo ago
Okay thanks I will check that out So this module just simply converts the binary file into a js file with a Uint8Array? Am I right?
jeff.hykin
jeff.hykin4w ago
Sorry for the late reply, but yep that's exactly what it does
Mqx
Mqx4w ago
Okay
jeff.hykin
jeff.hykin4w ago
It works for non-binary files too. A good example is: I wanted to compile a small web UI into single executable - problem: normally would use Deno.readTextFile("index.html") but then that means the html file needs to get shipped along with the executable. - solution: - use normal web bundler code to generate one HTML file - binaryify that HTML file - import instead of readTextFile - run deno compile - result: one self-contained executable In terms of deployment/CI Its still clunky to use, so if you have any suggestions let me know. It would probably be nice to have a "watch" feature where the binarifyied version of a file is auto generated
Mqx
Mqx4w ago
Only thing I dont like about this solution is that you commit generated files into your repo/package and this is not good.
NeTT
NeTT3w ago
Plug would be the best option imo
jeff.hykin
jeff.hykin3w ago
Yeah theres only so much that can be done while waiting on JS to support importing binary data