Touffy / client-zip

A client-side streaming ZIP generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] Directories

PierrotLL opened this issue · comments

Hi, client-zip is a great lib, thank you very much for your work.
It would be awesome to be able to organize files in sub-directories into the output zip (maybe it is already and I didn't found how?).
Thanks

Hello. While there is no explicit suport for it, sub-directories are in fact possible because they're not an actual entity in ZIP files, instead they are deduced from pathnames: if you create a file whose name begins with "folder/" then it will, de facto, be in that folder.

That said, we could add a more obvious sub-directories feature. But how would it work ? I've seen other libraries let you create a directory object with methods to add files to it. I don't want to do that because it would completely change the current design with a single streaming function. I am open to suggestions.

For example, we could have elements in the input iterable that have this form: {name: "dir", items: [await fetch(…), {name: "subdir", …}]}. It would make typing much harder because TypeScript doesn't like recursive types, though. And in the end, all it would do is prefix file names with the directory name and a slash.

That's awesome, exactly what I was looking for.
Thanks a lot :)