Archive programs for the PicoMite: 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 drive into one file
as a backup, or squeeze a big log file.

They run with MMBasic's RUN on the PicoMitePC3, PicoMiteHDMIUSB (with its
PSRAM enabled) and PicoMitePicoCalc firmware, V8.00.00b6 or later.
PicoMite_App_User_Guide.pdf, beside this file, describes them in its chapter
Archives: zip, unzip, gzip and tar.

Copy the zip folder to the root of the SD card (B:/zip), or to A:, 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
-------------
The options and the names come after the program's name, in one string:

  RUN "B:/zip/zip.app", "-r B:/backup.zip A:/*"
  RUN "B:/zip/unzip.app", "B:/games.zip -d B:/games"
  RUN "B:/zip/gzip.app", "-d B:/log.txt.gz"
  RUN "B:/zip/tar.app", "-xzvf B:/project.tar.gz -C B:/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, Chr$(34) in BASIC. 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.


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 B:/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
-----
- Extracted files have the time they were written, not the archive's, and
  files on A: go into an archive with the current time: the firmware cannot
  yet set a file's date, nor give an A: file's to a program.
- Ctrl-C stops any of them, and nothing half written is left.
- MMBasic reports a code other than 0 ("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: zip 4.4 s and unzip 3.1 s on a Pico
  Computer 3, 3.4 s and 2.0 s on a PicoCalc at 436 MHz.


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 firmware's repository (github.com/UKTailwind/PicoMite),
which fetches miniz from its release (github.com/richgel999/miniz).
