Archive programs for the Colour Maximite 2: zip, unzip, gzip and tar
=====================================================================

Four loadable programs for archives and compressed files, named after the
tools they copy and taking the commonest of their options: zip and unzip for
.zip files, gzip for .gz, and tar for .tar and .tar.gz (.tgz). Unpack a .zip
or a .tar.gz you have downloaded (with curl, say), put a folder or the whole
card into one file as a backup, or squeeze a big log file.

They are the PicoMite's programs, built from the same source with the
Colour Maximite 2's own SDK. They run with MMBasic's RUN on every
generation of the Colour Maximite 2, with firmware 7.00.00RC2 or later.
They were tested on a Generation 3 with 8.00.00b7.

Copy the zip folder to the root of the SD card (A:/zip), with a card reader
or a transfer that keeps a file's exact size, such as TFTP: XMODEM pads a
file, and RUN then refuses it.


Starting them
-------------
On the Colour Maximite 2 the options and the names come after the program's
name as you would type them on a PC, not in a string:

  RUN "A:/zip/zip.app", -r A:/backup.zip A:/games/*
  RUN "A:/zip/unzip.app", A:/games.zip -d A:/games
  RUN "A:/zip/gzip.app", -d A:/log.txt.gz
  RUN "A:/zip/tar.app", -xzvf A:/project.tar.gz -C A:/project

A name may have * and ? in its last part, as FILES takes them. A name with a
space in it goes in double quotes. They work in the current folder, as
MMBasic's own commands do. -h lists a program's options.


zip
---
  -r  go into folders            -j  the names only, not their folders
  -0  store, no compression      -1 .. -9  faster .. smaller (-6)
  -u  only new or newer files    -d  delete the names given (* and ?)
  -x  leave out the names after it   -D  no folder entries   -q  quiet

An archive that is there already is added to, and files with the same name
replaced. The new one is written as name.zip.tmp and put in place only when
it is complete, so an error or Ctrl-C leaves the old one as it was. A small
file that compressing would make bigger is stored as it is. The names are
kept without their drive: A:/games/x.bas is games/x.bas in the archive.


unzip
-----
  -l  list            -v  list in detail       -t  test every file's CRC
  -p  show on the screen, writing nothing      -d folder  extract there
  -o  overwrite without asking    -n  never overwrite
  -j  every file into one folder  -x  leave out the names after it
  -q  quiet

Names after the archive's choose what is extracted or listed (*.bas: * here
matches across folders). Before overwriting a file it asks: y, n, A (all) or
N (none). A name that would go outside the folder (../x, /x) is skipped.
Encrypted archives, and methods other than deflate, are not supported.


gzip
----
  -d  decompress        -k  keep the files given      -c  to the screen
  -f  force             -t  test                      -l  list
  -1 .. -9  faster .. smaller (-6)    -v  verbose     -q  quiet

As gzip does elsewhere, it deletes the file it has compressed or
decompressed, unless -k is given. A .tgz becomes a .tar.


tar
---
  -c  create (folders and all in them)   -t  list   -x  extract
  -f archive  always needed      -z  gzip (a name ending .tgz or .gz is
  compressed anyway; -t and -x find out for themselves)
  -C folder  -c: the names are in it; -x: extract into it
  -v  each name as it goes       -k  keep files that are there already
The letters may be given without the dash: czvf A:/progs.tgz progs

tar writes POSIX ustar, with GNU's record for a long name, and reads those
and the pax format of GitHub's downloads. Symbolic links and devices are
skipped; a hard link is extracted as a copy of its file.


Notes
-----
- Files put into an archive keep their own dates and times. Extracted
  files have the time they were written, not the archive's: the firmware
  cannot yet set a file's date.
- A file's whole path, with its drive and folders, can have at most 127
  characters, as everywhere in MMBasic. A name in an archive that would
  make a longer path is cut short by firmware 8.00.00b7 and earlier, so
  extract an archive with long names into a folder near the root
  (-d A:/x, -C A:/x).
- Ctrl-C stops any of them, and nothing half written is left.
- MMBasic reports a code other than 0 ("A:/zip/unzip.app ended with code
  1"): 1 means done with warnings (a name that matched nothing, a file
  skipped), 2 an error, 130 Ctrl-C.
- 1.3 MB of files of all kinds on a Generation 3: zip 2.3 s and unzip
  1.9 s, tar -czf 2.4 s and tar -xzf 2.0 s. gzip -9 compresses a 1 MB
  text file in 1.7 s.


Licences and source code
------------------------
zip.app, unzip.app, gzip.app and tar.app are under the MIT licence, with
miniz 3.1.2 (copyright Rich Geldreich, Tenacious Software, RAD Game Tools
and Valve Software), also MIT: licences/miniz-LICENSE.txt. Their source is
apps/zip in the PicoMite's repository (github.com/UKTailwind/PicoMite), the
same files as apps/zip in the Colour Maximite 2's (github.com/UKTailwind/
CMM2V1.5), which adds its own make.py; each fetches miniz from its release
(github.com/richgel999/miniz).
