This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-18
Channels
- # announcements (4)
- # aws (24)
- # babashka (118)
- # babashka-sci-dev (18)
- # beginners (56)
- # calva (2)
- # clojure (54)
- # clojure-dev (8)
- # clojure-europe (25)
- # clojure-gamedev (5)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (2)
- # conjure (1)
- # core-async (1)
- # data-science (3)
- # datomic (5)
- # emacs (8)
- # fulcro (4)
- # hyperfiddle (12)
- # interop (1)
- # jackdaw (4)
- # lsp (5)
- # mid-cities-meetup (5)
- # nbb (32)
- # off-topic (21)
- # reitit (5)
- # shadow-cljs (12)
- # sql (8)
- # vim (18)
- # xtdb (9)
If someone here wants to help with some research:
https://github.com/babashka/fs/issues/67
The issue is that fs/zip
should be able to add directories while omitting part of the the directory structure. So `foo/bar/ -> bar/ for example.
The homework is to find out how other platforms (Ruby, Python, Node and possible other libs do this.
In Python you need to use the lower level zipfile module and recurse down the dir structure and manually supply the filename in the write method: https://docs.python.org/3.10/library/zipfile.html#zipfile.ZipFile.write The dir walk is bit eased with Pathlib:
from pathlib import Path
def zipdir(parent_dir : str , ziph : ZipFile) -> None:
for file in Path(parent_dir).rglob('*'): # gets all child items
ziph.write(file, file.name)
the file.name
2nd arg to ziph.write is whats flattening ittheres no abstracted way to do this in py afaik
maybe an option like {:flatten true}
or {:preserve-heirarchy true}
flatten true would not cover the use case of adding foo/bar/baz and then have bar/baz in the zip
so its more of a selective filter?
hierarchal filter of sorts?
you don't know this use case? you have a directory src/foo/bar.clj
but you would like to have foo/bar.clj
in the zip
yeah i get around it with zipping src/* and others manually, havent had a need to just stripping one level yet
manually as in add all the needed parts step by step, not specifying what i need in a full dir
(zip archive "src/foo/*")
(zip archive "src/bar/*")
and more such calls
yep got it, just never thought of a need for this 😛
Ruby has a python like api too, seeing these two i think a :rename-fn
would be the most similar