8000 unzip extraction granularity is quite coarse · Issue #147 · babashka/fs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
unzip extraction granularity is quite coarse #147
Open
@sogaiu

Description

@sogaiu

I'd like to selectively extract from a .zip file if possible and don't see a way to do this currently.

As a proof-of-concept, I tried modifying unzip's options argument to take a function associated with a :satisfies key. The idea is for the function to be a predicate expecting a ZipEntry.

Would there be any interest in something like this?

--- fs/src/babashka/fs.cljc	2025-06-26 22:01:43.708713834 +0900
+++ fs.sogaiu/src/babashka/fs.cljc	2025-06-26 22:43:34.335138951 +0900
@@ -1000,10 +1000,11 @@
   "Unzips `zip-file` to `dest` directory (default `\".\"`).
 
    Options:
-   * `:replace-existing` - `true` / `false`: overwrite existing files"
+   * `:replace-existing` - `true` / `false`: overwrite existing files
+   * `:satisfies` - function expecting ZipEntry for file, return true => extract"
   ([zip-file] (unzip zip-file "."))
   ([zip-file dest] (unzip zip-file dest nil))
-  ([zip-file dest {:keys [replace-existing]}]
+  ([zip-file dest {:keys [replace-existing satisfies]}]
    (let [output-path (as-path dest)
          _ (create-dirs dest)
          cp-opts (->copy-opts replace-existing nil nil nil)]
@@ -1019,7 +1020,8 @@
                    new-path (.resolve output-path entry-name)]
                (if (.isDirectory entry)
                  (create-dirs new-path)
-                 (do
+                 (when (or (nil? satisfies)
+                           (and (fn? satisfies) (satisfies entry)))
                    (create-dirs (parent new-path))
                    (Files/copy ^java.io.InputStream zis
                                new-path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0