wwaawaw
wwaawaw

Reputation: 7127

Does ungzipping the result of concatenating two gzipped files always equal the result of concatenating the two files in their raw and ungzipped form?

In my brief tests, this has been the case, but I'm wondering if the property can be relied upon.

Does file3 always equal file4, no matter the contents of file1and file2?

cat file1 file2 > file3
gzip file1
gzip file2
cat file1.gz file2.gz | gunzip - > file4

# Are file3 and file4 necessarily the same?

Upvotes: 1

Views: 117

Answers (1)

Frank Farmer
Frank Farmer

Reputation: 39356

According to the man page, yes. This is documented behavior.

http://www.gnu.org/software/gzip/manual/html_node/Advanced-usage.html

Advanced usage

Multiple compressed files can be concatenated. In this case, gunzip will extract all members at once. If one member is damaged, other members might still be recovered after removal of the damaged member. Better compression can be usually obtained if all members are decompressed and then recompressed in a single step.

This is an example of concatenating gzip files:

 gzip -c file1  > foo.gz
 gzip -c file2 >> foo.gz Then

 gunzip -c foo is equivalent to

 cat file1 file2

Upvotes: 2

Related Questions