2

I'm using BASH in the terminal on Yosemite.

Is the zip command lossy?

I'm using it like this

zip -er ./output.zip ./input

-e encrypt

-r recurse

I am trying to avoid lossy compression when backing up data.

Would be super weak sauce if my backups came out corrupt :(

4
  • 3
    I know little about OSX, but based on my experience on Linux, I'd recommend tar for backup. Although zip is lossless, it doesn't contain all metadata.
    – v7d8dpo4
    Dec 26, 2016 at 3:25
  • @v7d8dpo4 Sounds like a good idea! Are you talking about tar -czf output.tar.gz /input/dir? My question then becomes, is G-Zip lossy? The zip command (according to man pages) is apparently not G-Zip. I'll bet there is a flag to use something other than G-Zip tho... Dec 27, 2016 at 20:05
  • Gzip is not lossy. The only common lossy compression methods are those for special kinds of files, such as JPEG and mp4. You can add -p and --xattrs to your tar command to preserve permissions and extended attributes. You don't have to use gzip. Look in the man page of tar (1), under the section "Compression options".
    – v7d8dpo4
    Dec 28, 2016 at 1:37
  • @v7d8dpo4 Yeah, the JPEG and mp4 type files are what worry me; there are a lot of .aif files in these projects. I think that is the most important part Dec 28, 2016 at 1:42

3 Answers 3

24

No, ZIP files are never compressed in a lossy way, nor would it really even be possible.

Lossy compression algorithms only work for data which can be approximated and still be recognizable to humans. Pictures and audio work for this, but not arbitrary data.

ZIP compression algorithms take arbitrary data, and without knowing what it is, compress it losslessly by finding redundant data, and mapping it out. There would be no way to know what part of the data might be approximated, which is why archive software use lossless compression.

14

The zip format does not use lossy compression, but the zip command is lossy in a different sense -- it does not include some kinds of Mac-specific file metadata in the archive. The metadata that gets left off is mostly unimportant. I'm talking about things like file tags, Spotlight comments, and such. Mostly.

If that's not good enough for you, you can use ditto, with the appropriate options. Here's an example, taken from the ditto man page:

ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
3
  • When you say Mac-specific metadata... I'm using this to backup Logic music projects and Logic is Apple proprietary, so I hope it doesn't leave out anything important. I tested it by duplicating one of my projects and it pulled up ok without any corruption Dec 25, 2016 at 18:04
  • 1
    @KolobCanyon I'm not familiar with the format or Logic projects, so I can't say for certain, but I'd expect them to be ok without metadata. The biggest risk I can think of is alias files, which become useless without the metadata that identifies them as aliases. So if the projects use aliases within themselves, they could break. I'd recommend using the ditto approach just in case. Dec 25, 2016 at 18:57
  • IIRC, the ZIP format also can't archive symlinks or hardlinks, but presumably you'd only have those within a single tree of files if you made them yourself. Dec 26, 2016 at 1:28
2

No, all of the compression methods supported in the .zip file format are lossless. See Wikipedia.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .