Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Does it take a longer time to delete files from a large tar zip and rar archive than a smaller one? I would think that for a file to be deleted from an archive, all the data that exists after the deleted file would have to be re-written to the archive, thus taking longer as opposed to a smaller archive where the amount of data to re-write is less... if not, how are these archives able to remove data from the middle of the archive without re-writing the rest of the data?

share|improve this question
add comment

4 Answers 4

You're exactly right. It depends a bit on the precise archive format and compression used, but generally, at a minimum, all the data stored "after" the deleted file must be rewritten.

share|improve this answer
    
To be perfectly honest, neither did you explain why the data stored needs to be rewritten. Maybe it's a vocabulary quandary, as rewriting can mean different things to different people. –  Doktoro Reichard Aug 29 '13 at 8:27
add comment

@Doktoro Reichard, but simply "telling" the archive that the file no longer exists cannot possibly be enough as the data is still occupied inside the archive, and still takes up space. It would be like removing a section of wood in the middle of a tree. Therefore, the data that is present after the deleted file(s) must be re-written to the archive, overwriting the files that one would wish to delete, then, because the data has moved backwards in the archive so to speak, the archive must be truncated to archivesize-filesize at the end to remove the dead space... Only now can the index table be updated with the new position of each file after the deleted file.

Following this logic, the only thing that would effect the amount of data that needs to be re-written is the byte position or where the file is located inside the archive. A file at the end of the archive could simply be truncated away rather quickly..

This however raises another question from the top of my head... How are file systems able to do exactly this, remove a file from the middle without re-writing data? Take for example a dynamic virtual disk.

share|improve this answer
    
(Although your post is better suited to a comment, not an answer). File systems are a little more tricky to explain fully, but in general they just flag the sectors the files occupy, so that the underlying system just sees the space occupied as free. No actual re-writing occurs when you delete a file, just when you are trying to write a new one to the same sectors. –  Doktoro Reichard Aug 29 '13 at 8:04
add comment

tar does not support compressed archive file modification. then you must completly rewrite tar archive, temporarly keep uncompressed one. it depends to tar archive format.

share|improve this answer
add comment

With regards to @David (the previous poster), I feel that the answer given is somewhat lacking.

Let's analyze the questions:

1. Does it take a longer time to delete files from a large tar zip and rar archive than a smaller one?

Yes it does, because the archive is bigger. However this is an absurd generalization. Considering the two main factors that may affect this: archive size and number of files archived.

If there is only one file archived, essentially what you're doing is deleting the archive itself. If there are many files, however, the archiving programs (and formats) have different ways to treat files.

Tar, for instance, was meant to be a sequential file storing format for storing tape archives. One of the disadvantages is that, since there is no "table of contents", it needs to iterate through the whole archive to find a folder or a file.

Rar, on the other hand, has an option to make solid files. A solid file is an archive where all information was previously treated as a big stream. This means that, whenever someone wants to access, edit, add or delete a file, the entire archive must first be decompressed, and then recompressed.

And now we come at something new: compression ratio. If the files are highly compressed, it will take more time, no matter the algorithm, to access them. Although this is dependent on the kind of files being compressed (text files (not .docx) have high redundancy so they can be de/recompressed quickly)

2. How are these archives able to remove data from the middle of the archive without re-writing the rest of the data?

The reasoning before this question isn't always valid, except for the rar "solid" archive.

Barring Tar (for reasons shown on the Wikipedia link), both zip and rar have something of a "table of contents" that enables the archives to selectively extract data. All this is done without recompressing the existing data, although some things need to be altered inside the archive to tell him that the file no longer exists.

Think of an archive as a small box, where each file is crammed and squeezed in order to fit it. As soon as you take one item, the box srinks in order to fill the space.

share|improve this answer
    
You never answered the question you posed in "2". How is it possible? The question wasn't about extraction or recompression but about re-writing. –  David Schwartz Aug 29 '13 at 3:28
    
I actually did, if you read about the "table of contents". Essentially each file inside the archive is compressed individually. The only re-writing that might happen is only to shift the files that come after (the contents) to the positions occupied by the deleted file. But that is trivial, as you don't need to alter anything in the compressed files. The best comparison would be to delete a line of text inside a document, where each line is a file. You didn't have to re-write all other files just to delete one (except in the rar 'solid' case). –  Doktoro Reichard Aug 29 '13 at 8:02
    
So, if the file comes at the beginning of the archive, then you do have to rewrite the entire archive, right? How is that trivial? –  David Schwartz Aug 29 '13 at 18:01
    
@David It's trivial in the sense you don't need to reprocess the remaining files, all the heavy work has already been done. Again, I refer to you to my analogy: if you delete a line at anywhere on the document, you don't need to write again all lines. –  Doktoro Reichard Aug 29 '13 at 18:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.