缓存以更快地重新压缩给定的文件夹 edit/add/delete

Caching for faster recompression of folder given edit/add/delete

总结

假设我在发送到服务器之前想 compress/zip 文件夹中有大量文件。将它们压缩在一起后,我意识到我想要 add/remove/modify 一个文件。是否可以避免从头开始整个压缩过程?

详情

我想可能有一些方法可以缓存部分压缩过程(无论是 .zip.gz 还是 .bzip2),使压缩增量,即使它会导致次优压缩。例如,考虑朴素字典编码压缩算法。我想应该可以在单个文件上使用编码字典而无需重新处理所有文件。我还想象,随着更多文件 added/removed/edited.

,这种缓存机制提供的压缩损失会增加

类似问题

有两个问题与此问题相关:

  1. 一个C implementation, which implies it's possible
  2. A C# related question,这意味着可以先压缩单个文件?
  3. 一个PHP implementation, which implies it isn't possible without a special file-system
  4. 一个Java-specific adjacent question, which implies it's semi-possible?

查阅zip的手册页,有几个相关命令:

更新

-u
--update

Replace (update) an existing entry in the zip archive only if it has been modified more recently than the version already in the zip archive. For example:

    zip -u stuff *

will add any new files in the current directory, and update any files which have been modified since the zip archive stuff.zip was last created/modified (note that zip will not try to pack stuff.zip into itself when you do this).

Note that the -u option with no input file arguments acts like the -f (freshen) option.

删除

-d
--delete

Remove (delete) entries from a zip archive. For example:

    zip -d foo foo/tom/junk foo/harry/\* \*.o

will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any path). Note that shell pathname expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling zip to match on the contents of the zip archive instead of the contents of the current directory.

是的。 zip 文件中的条目都是单独压缩的。您可以 select 并仅从任何 zip 文件中复制所需的压缩条目以制作新的 zip 文件,并且您可以将新条目添加到 zip 文件中。

不需要任何缓存。

例如,zip 命令执行此操作。