As per Wikipedia, data compression or file compression can be understood as a process of reducing the size of a particular file/folder/whatever data while still preserving the original data. Lesser file size has a lot of benefits as it will then occupy lesser storage area giving you more space for other data to occupy, transfer the file faster as the size is lesser and various other perks unlock upon file compression. The compressed files are stored in the form of compressed file extension folders such as “.zip“,”.rar“,”.tar.gz“, “.arj” and “.tgz“. Compression reduces the file size to maximum compression size. If it cannot be compressed further then the size shall remain the same and not lesser.
After data is compressed we often feel the need to undo them in order to make them readily accessible. This undoing process is called uncompression. The process of extracting a normal file/folder from a compressed file is termed as uncompression.
But How to Uncompress the File?
There are various software that performs such tasks for us; one best example I know is WinRAR/WinZip. They are capable of compressing and uncompressing data files. But how long do we depend on software alone? Most of their features come paid and apart from the financial aspect, do we coders have to eternally depend on outsourced applications to fulfill our needs? Or can we dig out our own ways to meet our requirements? Well, data uncompression can also be done manually. One such manual method is discussed below using GoLang.
Case scenario: Files present inside a folder that’s archived. The program extracts all files to the target destination.
My pwd path : ../src/myprograms/unzip and zip Source zip folder : ../src/myprograms/unzip and zip/compression-test.zip Compression-test.zip contains : Hello world.txt main.go Destination path : ../src/myprograms/unzip and zip/uncompressed files Output on my screen: Unzipped the following files: uncompressed files\compression-test\Hello world.txt uncompressed files\compression-test\main.go
Visual Demo on Visual Studio Code: