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:
- How to Create an Empty File in Golang?
- How to Rename and Move a File in Golang?
- How to Delete or Remove a File in Golang?
- How to Truncate a File in Golang?
- Checking the Given File Exists or Not in Golang
- How to Read a File Line by Line to String in Golang?
- How to convert a slice of bytes in uppercase in Golang?
- Golang program that uses fallthrough keyword
- math.Lgamma() Function in Golang with Examples
- math.Float64bits() Function in Golang With Examples
- How to check equality of slices of bytes in Golang?
- atomic.AddInt64() Function in Golang With Examples
- atomic.StoreInt64() Function in Golang With Examples
- reflect.FieldByIndex() Function in Golang with Examples
- string.Contains Function in Golang with Examples
- bits.Sub() Function in Golang with Examples
- How to convert a slice of bytes in lowercase in Golang?
- io.PipeWriter.CloseWithError() Function in Golang with Examples
- Import in GoLang
- time.Round() Function in Golang With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.