Tapzip and pipe

A little job I had to do today was to write a script (unix) to zip a file before transmitting it to a Windows system. No problem, we have zip installed…

zip file.zip file.txt

Then they decided that it was in ASCII Latin1 and they wanted it in UTF-8. Again, no problem

iconv -f ISO-8859-1 -t UTF-8 file.txt | zip file.zip -

The snag is that zip includes not only the compressed file in the output, but also headers giving details of the file name etc. In the case above the input comes from a pipe and there is no file name so it creates an entry called - (just a hyphen) which is not very useful. The unix unzip command has an option to get around this.

unzip -p file.zip > file.utf8

or you can use funzip if your implementation includes it.

funzip file.zip > file.utf8

I have no idea what they can do on Windows. I may have to do it the slow way and create an intermediate file with all the housekeeping, security and management that involves 🙁

Exercise for the reader: If you just unzip file.zip from above it creates a file called -. How do you do anything with it?

6 Responses to “zip and pipe”

^ Top