commandline zip packer / unpacker util using libzip

User projects written in or related to FreeBASIC.
Post Reply
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

commandline zip packer / unpacker util using libzip

Post by thrive4 »

description
A 'proof of concept' utility that allows for
packing (recursive) and unpacking of files
and folders from and to a zip archive.

Additionally it has a -t option illustrating
passing a text string (data) directly
from freebasic to a created zip file.

From a code perspective there are numerous
issues to keep in mind,
- data integrity,
- the rather shacky state of libzip,
- the size and number of dll's needed to utilize the lib
- the discrepancy of the bindings
| (zip.bi used and the one bundled with fb version)
- the lib utilizes 'unixtime' internally
| which is ok but still needs closer scrutiny
| see separate posting with unixtime routines
viewtopic.php?t=32414

Intended use is mostly educational but might
be useful to some as bare bones conversion util.

compile
with following files in same dir as code:
libbz2-1.dll
libgcc_s_dw2-1.dll
liblzma-5.dll
libwinpthread-1.dll
libzip.dll
libzstd.dll
zlib1.dll
zip.bi (included in zip package of srvaldez)

usage
extract: cmdzip.exe <archive>.zip <folder>
example: cmdzip.exe test.zip test
extracts all files from archive test.zip to folder test

add: cmdzip.exe <path or file> <archive>.zip
example: cmdzip.exe g:\data\text\*.txt text.zip
adds all the .txt files in g:\data\text to the archive text.zip

options
via \conf\conf.ini\
[output]
' preserve path file to archive
preservepath = false
' preserve datetime stamp file from and to archive
preservedate = true

Tested and compiled on windows 7 / 10 as 32bit app

release (32bit windows)
https://github.com/thrive4/utill.fb.cmdzip/releases

source
https://github.com/thrive4/utill.fb.cmdzip

requirements
libzip 1.10.1 or up
https://github.com/nih-at/libzip
the windows (32bit / 64bit) dlls can be found at:
viewtopic.php?p=300696
with thank to srvaldez for kindly posting them

special thanks
tips on commandline parsing via:
viewtopic.php?t=31889 code by coderJeff
with courtesy to srvaldez for providing dlls windows 32bit / 64bit
see viewtopic.php?p=300605&hilit=open+zip#p3006
unixtime:
courtesy adeyblue
see viewtopic.php?p=267242&hilit=ctime&sid= ... 8c#p267242
and michaelw viewtopic.php?p=164305
andykmv
Posts: 58
Joined: Feb 12, 2015 9:50

Re: commandline zip packer / unpacker util using libzip

Post by andykmv »

some good stuff there - especially the time stuff i am trying to nut out - when using zip_stat_index - translating the timestamp of the file in zip to a useable datatype would have taken a bit of nutting out; thankfully you have already beaten that one :D

when i am finished hacking away i'll add some useful bits to compliment yours. :D
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

Re: commandline zip packer / unpacker util using libzip

Post by thrive4 »

Good to hear that the code was of some use to you.
Have fun with it!

Bye the bye some other avenues worth while looking into:
viewtopic.php?t=23706
7zip Example - by nimdays

or writing an shell wrapper around:
https://www.7-zip.org/download.html
specifically 7za.exe (roughly 800K)
it has quite generous terms of use:
https://www.7-zip.org/faq.html (see Developer FAQ)
is available on nix, windows and macOS (64bit / 32bit)
and has been around for quite some time so,
generally speaking, all the rough edges have
been ironed out....
Post Reply