What's the standard or established way to load a r...
# multiplatform
e
What's the standard or established way to load a resource (e.g., a JSON/XML file) from
commonTest/resources
? I'm using the
kotlin.test
infrastructure to test code in common.
e
Thanks @mbonnin! Another option I've just found out https://github.com/goncalossilva/kotlinx-resources
m
That works too albeit does more things. By a quick glance, looks like it copies files around to workaround the current working dir issue from Jesse's article.
Also looks like it's loading the whole file in memory which might be an issue if you have large files
e
Also looks like it's loading the whole file in memory
True. Tho most platforms offers a way to stream data. I think it's not done because nobody had the use case
true story 1
m
Yea for XML no one cares πŸ˜„
640kb should be enough for everyone, right ? blob upside down
e
I can open a new issue about streaming bytes. Would be useful on the JVM and on Node.js as a starter
πŸ‘ 1
I do have big payloads in XML, but for tests I don't think loading them all in memory is a big deal. Considering the other approach is code it myself, I'd prefer to keep it into a library
m
Yea, any big payload you have will be negligeable compared to the IJ + Gradle + Kotlin compiler 16GB combo πŸ˜„
πŸ˜‚ 2
Jesse's article is really good. I don't think you'd end up writing a lot more code. If you really want to write as little code as possible, you could even turn it into its own Gradle plugin + runtime
e
I need to investigate more, tho I don't think I can justify spending a lot of time on this while building an MVP. Just tagging in the lib author @goncalossilva Maybe he did already consider the streaming part but it was not doable
πŸ‘ 1
g
I did not consider streaming and it's not been requested. 😊 Happy to look into it soon.
Thanks for tagging!
FWIW I've tested the current approach with files up to 2GB, though it breaks in one of the platforms(?) after that.
e
Hey there @goncalossilva I'm just testing out your library on JVM and Node (will probably add Windows next week) and it's working as expected. Thanks! I think streaming can be of good value for those running in more constrained CI environments. I do have a dedicated VM with 64 gigs of RAM, so for me it should not be an issue, at the moment. Java has a dedicated API (StAX) for it. Maybe @mbonnin has more complex requirements
πŸ‘ 2
Btw, for context, I'm using it to test a custom network protocol (which can carry JSON and XML in its payload)
m
No more complex requirement from my side, just the general observation as an industry, we tend to take all those GB for granted these days and I wish we could be a bit more conservative sometimes
plus1 2
g
Agree, it's a disappointing trend. Truth is, kotlinx-resources started by wrapping @dellisd's gist, extending it to JS browser using a trick with karma, and providing it in a ready-to-use library+plugin combo. And since it was purely for testing, and solved my own requirements (mostly, tiny files), I haven't put much thought into more efficient ways of loading resources. But with the library becoming more popular and seeing more use cases, it makes perfect sense to provide more efficient APIs. Within the next few weeks I'll see what's available across platforms. 😊
πŸ’™ 2
e
@goncalossilva forgot to ask about text encoding. When you read the resource as a string, are you using UTF-8?
g
Yes. Specifying the encoding is something I want to add at some point.
πŸ’― 1
e
@goncalossilva oh thanks! My socket tests are all based on UTF-8 data, so wanted to be sure the default for you was indeed UTF-8.
βœ… 1