-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add Zip support #310
Add Zip support #310
Conversation
Resolves com-lihaoyi#161. Add Zip support. `os.zip(path)` to read/write zip file. File will be created if not exists. `zipFile / subPath` to get a path. Should be able to support all the file operations like copy, move, delete and so on.
Hi @lihaoyi , this is ready for review |
@wb14123 looks like a good start. Need a few more things according to the original ticket:
Below are the various flags on my OS-X laptop, I assume Linux zip has similar ones
We don't need to support all of them verbatim, but on a case by case basis:
Exactly which flag goes into which category is a subjective judgement. In terms of next steps, how about you go through the list of zip flags (either the ones I provided or the ones on your computer, doesn't really matter) and categorize them into the 4 categories above, and list out your categorization as part of the PR description. Then we can ensure that the ones that deserve special support are supported, and the ones that can be emulated via other workflows have those workflows tested and exercised. Lastly, we need to include this in the documentation. One you have the categorization/implementation/tests finalized, it should be pretty quick to copy paste the necessary parts of each into the |
import java.nio.file.{Path => _, _} | ||
import collection.JavaConverters._ | ||
|
||
class zip(zipPath: Path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since fs
is created internally, shouldn't the class zip
implement Closeable
?
|
||
private val fs = FileSystems.newFileSystem( | ||
URI.create("jar:file:" + zipPath.wrapped.toString), | ||
Map("create" -> "true").asJava |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could a Map[String, String]
be an optional parameter to the class constructor with this as the default value? That would make it configurable from the outside.
Pulls in changes from #316 and #310 and cleans it up Mostly documented in the readme.adoc. Major APIs added: - `os.zip`: create or append to an existing zip file on disk - `os.zip.stream`: create a new zip file but write it to an `java.io.OutputStream` rather than a file on disk - `os.unzip`: unzip a zip file on disk into a folder on disk - `os.unzip.stream`: unzip a zip file from an `java.io.InputStream` into a folder on disk - `os.unzip.list`: list the contents of a zip file - `os.unzip.streamRaw`: low-level API used by `os.unzip.stream` and `os.unzip.list`, exposed in case users need it - `os.zip.open`: Opens a zip file as `java.nio.file.FileSystem` and gives you an `os.Path` you can use to work with it Hopefully these are APIs we can start using in Mill rather than `"zip"` subprocesses or ad-hoc helpers like `IO.unpackZip` Limitations: * Use of `java.nio.file.FileSystem` is only supported on JVM and not on Scala-Native, and so using `os.zip` to append to existing jar files or `os.zip.open` does not work on Scala-Native. * Also `os.zip` doesn't support creating/unpacking symlinks or preserving filesystem permissions in Zip files, because the underlying `java.util.zip.Zip*Stream` doesn't support them. Apache Commons Compress can work with them (https://commons.apache.org/proper/commons-compress/zip.html), but if we're sticking with std lib we don't have that * Bumps the version requirement to Java 11 and above, matching the direction of the rest of com-lihaoyi. Probably not strictly necessary, but we have to do it eventually and now is as good a time as ever with requests already bumped and Mill bumping soon in 0.12.0 --------- Co-authored-by: Chaitanya Waikar <[email protected]>
Resolves #161. Add Zip support.
os.zip(path)
to read/write zip file. File will be created if not exists.zipFile / subPath
to get a path. Should be able to support all the file operations like copy, move, delete and so on.