-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write a .zip #1442
Comments
Maybe something like this?
You’d create a real or fake FileSystem, populate a directory with content, then create a .zip from that content. One drawback of this API is it’s awkward to create entries from a stream, like an HTTP response. |
Another option:
|
A couple more considerations:
I suspect these are a deal-breaker for the APIs that use a Here’s another API proposal. It ends up looking a lot like Moshi’s JsonUtf8Writer in name & usage. class ZipWriter(sink: BufferedSink) : Closeable {
inline fun <T> file(
file: Path,
compress: Boolean = true,
lastModifiedAtMillis: Long? = null,
lastAccessedAtMillis: Long? = null,
createdAtMillis: Long? = null,
writerAction: BufferedSink.() -> T,
): T
fun directory(
dir: Path,
lastModifiedAtMillis: Long? = null,
lastAccessedAtMillis: Long? = null,
createdAtMillis: Long? = null,
)
}
inline fun <T> BufferedSink.writeZip(writerAction: ZipWriter.() -> T): T And a usage example of the above: FileSystem.SYSTEM.write("greetings.zip".toPath()) {
writeZip {
file("hello.txt".toPath()) {
writeUtf8("Hello World")
}
directory("directory".toPath())
directory("directory/subdirectory".toPath())
file(
file = "directory/subdirectory/child.txt".toPath(),
compress = false,
lastModifiedAtMillis = Clock.System.now().toEpochMilliseconds(),
) {
writeUtf8("Another file!")
}
}
} |
I think I’d canonicalize input paths by stripping a leading |
I think I’d default timestamps to null/absent/0 rather than grabbing the host machine’s time and jamming that in there. Too many tools that produce |
I think I’d produce |
I think I’d stream output to a |
That API in #1442 (comment) looks really good and would suit most of my needs. I have a bunch of app of which you can export your data. Everything that is a table in my sqlite tables just gets a corresponding json file where I dump all the data. Media files such as videos/images are stored such that they preserve their relative path from class ZipWriter(sink: BufferedSink) : Closeable {
fun copy(
source: Source,
compress: Boolean = true,
): T
} Or would this just be achievable by something like this? file("attachments/image_1664623103090.jpg".toPath()) {
writeAll(fileSystem.source("attachments/image_1664623103090.jpg"))
} |
@vanniktech We could include all kinds of helpers, possibly as extensions.
|
Is there already some functionality to create a simple ZIP file of a directory or any ZIP file at all for native targets (iOS in my case)? |
@mipastgt not yet! |
We should design an API to create a .zip file.
See also:
#1408
The text was updated successfully, but these errors were encountered: