rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
623 stars 113 forks source link

Is it possible to remove items from archive? #55

Closed vladimir-kraus closed 11 months ago

vladimir-kraus commented 2 years ago

Feature description

The title speaks for itself: is it possible to remove/delete items directly from existing archive?

By "directly" I mean without extracting the archive first to temporary folder on a disk, then removing the items from the disk and compressing it again.

After experimenting with 7z command line tool, it seems to me that 7zip is able to do this. There is a command option for this https://sevenzip.osdn.jp/chm/cmdline/commands/delete.htm and by observing the speed of this operation, it definitely is faster than extracting and compressing back.

Additional context

No response

Code of Conduct

rikyoz commented 2 years ago

Hi!

The title speaks for itself: is it possible to remove/delete items directly from existing archive?

Unfortunately, no, at least with the current stable version (v3.1.4).

However, it will be possible with the next major version (v4.0). It's actually already implemented in a new class called BitArchiveEditor, which allows editing already existing archives. It allows to add, delete, update, and rename the items in the archive.

By "directly" I mean without extracting the archive first to temporary folder on a disk, then removing the items from the disk and compressing it again.

The removal of the file will be "direct" because the class will not perform any extraction. However, the class has the same behaviour as 7-zip, i.e., it creates a temporary archive where 7-zip copies all the compressed data but the item(s) to be deleted.

If you're interested in the API, please check https://github.com/rikyoz/bit7z/blob/pre-release/v4.0.0-beta/include/bitarchiveeditor.hpp. Roughly, it will be possible to use some code like the following:

BitArchiveEditor editor{ lib, L"path/to/archive.7z", BitFormat::SevenZip };
editor.deleteItem(L"folder/compressed_file.txt"); // path of the file to be deleted from the archive
editor.applyChanges();

Note: the actual deletion only happens when you call the applyChanges() method; in this way, you can chain multiple edit operations and apply them all together to the archive.

rikyoz commented 11 months ago

Implemented in v4.0.0.