There are two things you can do here.
- Serialized the directory structure using something like
tar
. For tar, uselibarchive
. - Switch from using
gzip
tozip
.zip
(also called PK zip) can compress a directory structure instead of just a single file. Forzip
look intominizip
.
As @Kevin stated in a comment, you already have a tar
ed file. If you want to go with a .tar.gz format (sometimes given as .tgz), then you only need to decompress the bzip2
part of file.tar.bz2
, which will leave you with a file.tar
. At that point you can recompress with gzip.