https://github.com/imarsman/gozip
An implementation of the zip utility in Go as an exercise
https://github.com/imarsman/gozip
Last synced: about 1 month ago
JSON representation
An implementation of the zip utility in Go as an exercise
- Host: GitHub
- URL: https://github.com/imarsman/gozip
- Owner: imarsman
- License: apache-2.0
- Created: 2021-09-07T15:41:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-10T01:51:36.000Z (almost 4 years ago)
- Last Synced: 2025-02-17T05:11:15.695Z (4 months ago)
- Language: Go
- Size: 103 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gozip
An implementation of the zip utility in Go as an exercise.Zip was first implemented in 1989 by the PKZIP corporation. Its specification
was put in the public domain in the same year (see
[Wikipedia](https://en.wikipedia.org/wiki/ZIP_(file_format))) for further information.Go has a good library for the zip protocol. This project provides a way to
explore the protocol, find any issues, and overall learn more about the things
that are involved, namely i/o and file handling. I also find it generally useful
to learn how to pay close attention to exactly how things work.There are a huge number of possible options for the zip utility. I will likely
not implement most of them. As far as I can tell the Go zip library does not
work with updating an existing archive. In testing extra bytes ended up being
added to the archive with each update. For this reason the code first gets an
inventory of all files in an archive along with things like modified time and
then uses that to create a new archive after deleting the old one. This is not
ideal and if possible a switch will be made to updating rather than replacing.Zip has enough arguments without also trying to implement unzip. I'll save that
for another project.## Arguments
* `gozip -h` - print usage information
* `gozip -l ` - list contents of zipfile
* `gozip ...` - default to freshen
* `gozip -a ...` - add and update files
* `gozip -u ...` - update if newer and add
* `gozip -f ...` - only update newer files already in archive## Usage
To build
`go build .`
To run tests
`go test -v .`
## Simple tests
It's not as fast as the native zip.
```
time for i in {1..1000}; do ./gozip test/archive2.zip ./sample/; donereal 0m6.936s
user 0m3.693s
sys 0m2.772stime for i in {1..1000}; do zip add -q test/archive2.zip ./sample/; done
real 0m4.237s
user 0m2.072s
sys 0m1.760s
```## Notes
Creating new archives and listing them works
```
compressed uncompressed date time name
---------------------------------------------------------------------------
3495 7210 2021-09-08 19:02:28 sample/1.txt
2330 4621 2021-09-08 19:02:28 sample/2.txt
1174 2178 2021-09-08 19:02:28 sample/3.txt
1021 1827 2021-09-08 19:02:28 sample/4.txt
497 918 2021-09-08 19:02:28 sample/5.txt
3495 7210 2021-09-07 23:26:00 sample/orig/1.txt
2330 4621 2021-09-07 23:26:00 sample/orig/2.txt
1174 2178 2021-09-07 23:26:00 sample/orig/3.txt
1021 1827 2021-09-07 23:26:00 sample/orig/4.txt
497 918 2021-09-07 23:26:00 sample/orig/5.txt
---------------------------------------------------------------------------
17034 33508 10
```Wherever a feature of the zip utility is implemented an attempt will be made to
impliment it to behave identically.