go-sciter
go-sciter copied to clipboard
A new and simpler method for resource packing.
I believe rice
is very nice but an overkill for such a simple task. It also looks very different than how sciter does it with packfolder
. We can do the same by using go generate
.
I made a tool go-packfolder
with less than 100
lines of code (based on rice.go
). Please check it here: https://github.com/dodobyte/go-packfolder
If you have this small tool, the only thing you need to change is adding a comment line anywhere you like in your code:
//go:generate go-packfolder -o=res.go -p=main res
and this line as before: handleDataLoad(w.Sciter)
That's it, now you can call go generate
and have your .go file with all the resources and helper code.
If you like my solution, you can put the code in go-sciter code base, and i will happily delete my repo (one of the reasons i didn't want to use rice is that i don't like too many dependecies).
Even if you don't do that, still this issue can be helpful for people who has issues with packing resources.
Thanks.
Note: -o
is output .go file and -p
is package name (default is main
). res
is resource directory.
A view from generated code:
Hi. Thanks for bringing this up.
Well, according to your code, it's just a map of file names and their data, encoded with Go json convention (e.g. binary data comes as base64 string). I agree, it is simpler indeed :)
However, it comes with memory and speed overhead. I think, a zip archive would be more efficient and even more simple, because Sciter handles it out of box. Or, we can add support for the real packfolder: just need to encode its binary output in Go source and call a couple of Sciter API functions in data handler. With go:generate
it will be very convenient.
:heavy_check_mark: And also we can ask packfolder
to support output in Go format.
Hi @Pravic,
Of course we don't decode base64 everytime we need a resource, in handleDataLoad
function i unmarshal packed
to unpacked
. So it's a map from file name to it's byte slice, as fast as it can get.
We definitely can compress it, it would be very easy with go. Just let me know the details and i implement them.
And also we can ask packfolder to support output in Go format.
That would be nice to have.
Well, packfolder
supports output in Go since SDK 4.1.6. Want to add bindings for Sciter archive? It's just 2 functions.
Nevermind, they have been added in #86 long time ago. I've merged and fixed it (#141). Should work (haven't tested yet).
The release of Go 1.16 introduced a new embed package, as part of the standard library, that aims to provide a standard approach to resource packing. I think it would make sense to supplant rice with that package some time in the future. However, this would mean setting Go 1.16 as the minimum supported version. What are your thoughts on this?
Why can't we support both, rice and embed?
You can. But since this issue remained open, I assumed there was an interest in replacing rice.