There are numerous compression algorithm out there for file compression. Here come 5 examples with how-to-do links from this blog.
Compressing individual files
The following algorithms can be used to compress a single file. E.g. source.txt will be compressed to source.txt.gz.
Compressing a group of files
The following algorithms can be used to group files and then compress the file group.
Read all posts dedicated to file I/O here.