Does ktor support creating zip files in memory onl...
# ktor
m
Does ktor support creating zip files in memory only to send to the client? If not, how would I do that?
d
I guess your best bet is to use any library you would use for the JVM to create a zip in-memory (or in an OutputStream, that could end in memory too), and then serve its bytes or its stream depending on the size of the zip and your requirements
You can send any raw bytes with
call.respondBytes
m
So how would I create a zip file in memory and add files (tempfile is acceptable too)? I've seen some solutions on SO, but they were all for Java and I have no clue how I'd port that to Kotlin, or if there are good kotlin alternatives.
d
you can just copy that snippet and paste it inside a .kt file, if you are using intellij, the code will be detected as Java and converted automatically from Java to Kotlin
m
How do I do it in notepad++?
d
#getting-started
And BTW, I meant not to ask about that there, but about getting started on how to use kotlin there. Ktor is a Kotlin library, and in this channel we treat ktor stuff. If you plan to use Ktor, you should be familiarized with Kotlin first. There is a quickstart about kotlin here: • https://kotlinlang.org/docs/reference/basic-syntax.html I suggest you to use IntelliJ. Kotlin is supported in IntelliJ Community Edition, that is completely free. Also you can use eclipse too. I used notepad++ for a lot of years while coding PHP, but I strongly suggest you to switch to a proper IDE for coding statically typed languages even when if the language induces types. Using IntelliJ would also help you to convert Java to Kotlin and would reduce the learning curve if you have some Java or similar language background. If not, there is no magic bullet: if you plan to use a technology stack, you have to learn its parts. Also, please read the guideliness for this slack community: https://kotlinlang.org/community/slackccugl.html In that page you can find the list of channels and what could you expect from each channel, and some behaviour tips to keep the community healthy and a great place to be. Since this is a Kotlin community maybe people won’t help you with trivial stuff not kotlin related. You can use stackoverflow for that and/or similar places instead. If you have trouble in converting some Java to Kotlin or questions about Kotlin syntax, people here could help you. And of course, for ktor-specific topics we are here to help too 🙂
m
Thanks. I feel like I know most of what I need to know from Kotlin (no Java background sadly, only python and lua) but I doubt I'll need IntelliJ. Notepad++ and Neovim is more than enough. I'll look into those guidelines and find what channels I need.
d
Nice. Of course you don’t need it. I don’t need it either. But with notepad++ you wont be able to refactor or rename in big codebases or see errors while writing. And you will have to compile to see the errors that you would have fix immediately if the editor points you. And no proper completion and you will have to spend a lot of time checking documentation snd guessing variable types. Even if you plan carefully everything from the very beginning, nobody does everything perfect and refactoring is required for midterm to longterm projects or the codebase ends being a mess. And you have to spend your brain time in dealing with api names, syntax and stuff. True story. Still I used notepad++ a lot of years more before I started working for a company and realized about that myself even for untyped PHP codebases, that helped a lot. Ofc thats my story, and you can do whatever you like. If you have tried IntelliJ with Kotlin before and decided to not use it, thats ok, but if not, I encourage you to just try it for a couple of days and see if your productivity increases :)
l
we are creating gzip files in memory and sending them to the user without creating temp files. We extended the WriteChannelContent class and used the outputStream from the channel in the writeTo method.
👍 1