nfriedly / node-bestzip

Provides a `bestzip` command that uses the system `zip` if avaliable, and a Node.js implimentation otherwise.
MIT License
80 stars 16 forks source link

Delete exists before create options ? #49

Open abcfy2 opened 3 years ago

abcfy2 commented 3 years ago

Native zip behavior is update exists zip file. We should add a option like delete exists before create. Thanks.

From man zip description:

       where archive is a new or existing zip archive and inpath is a directory or file path optionally including wildcards.  When given the name of an existing zip archive, zip will replace iden‐
       tically named entries in the zip archive (matching the relative names as stored in the archive) or add entries for new names.  For example, if foo.zip  exists  and  contains  foo/file1  and
       foo/file2, and the directory foo contains the files foo/file1 and foo/file3, then:

              zip -r foo.zip foo

       or more concisely

              zip -r foo foo

       will replace foo/file1 in foo.zip and add foo/file3 to foo.zip.  After this, foo.zip contains foo/file1, foo/file2, and foo/file3, with foo/file2 unchanged from before.

       So if before the zip command is executed foo.zip has:

               foo/file1 foo/file2

       and directory foo has:

               file1 file3

       then foo.zip will have:

               foo/file1 foo/file2 foo/file3

       where foo/file1 is replaced and foo/file3 is new.
abcfy2 commented 3 years ago

I find a simple solution:

zip -r - . > ../data.zip

See: https://unix.stackexchange.com/questions/299161/unix-zip-command-is-updating-existing-archive-instead-of-creating-a-new-one