bit7z icon indicating copy to clipboard operation
bit7z copied to clipboard

[Feature Request]: bitCompressor with update = false should recreate the archive

Open cobian-test opened this issue 1 year ago • 1 comments

Feature description

The behavior right now is that if compressor.setUpdateMode(false); and the archive already exists, an exception is thrown. It could be easy to fix by checking the existence of the file and deleting the archive before opening the output stream. The same (and most important) thing should be done if creating volumes, because every existing part raises an exception now.

Regards

Additional context

No response

Code of Conduct

cobian-test avatar Aug 10 '22 23:08 cobian-test

Hi!

The behavior right now is that if compressor.setUpdateMode(false); and the archive already exists, an exception is thrown.

This behavior is actually going to change with the next version (currently in beta). The setUpdateMode will not accept a boolean parameter anymore, but rather an enum value which can be one from UpdateMode::None, UpdateMode::Overwrite, and UpdateMode::Append.

  • UpdateMode::None (the default mode) will give the same behavior as the setUpdateMode(false) in bit7z v3: if the output archive already exists, an exception is thrown.
  • UpdateMode::Overwrite: if the output archive already exists, then:
    • If it already contains an item with the same path as the new file, the archive will be updated by overwriting the content of the item.
    • Otherwise, bit7z will update the archive by appending the new item.
  • UpdateMode::Append will be equivalent to the setUpdateMode(true) in bit7z v3, with the new items appended to the already existing archive.

It could be easy to fix by checking the existence of the file and deleting the archive before opening the output stream. The same (and most important) thing should be done if creating volumes, because every existing part raises an exception now.

I think it might be really useful, thanks for your suggestion! The only problem I can see is that deleting the already existing archive might not be the best default behavior desirable by the library's user. So what I'm probably going to do is add another update mode to the next version, something like UpdateMode::OverwriteArchive, which should make bit7z behave just like you suggested.

rikyoz avatar Aug 14 '22 08:08 rikyoz

Implemented in v4.0.0

rikyoz avatar Oct 01 '23 19:10 rikyoz