Home / Alt manpages / prezip-bin(1)

  • prezip-bin(1)
  • User command
  • linux

Compress and Restore Sorted Word Lists with prezip-bin

prezip-bin turns a sorted word list into a compact binary file, and this guide proves the round trip works before you trust it. It covers compressing, restoring, comparing byte-for-byte, and feeding the result into Aspell's dictionary builder. Allow about ten minutes for a small list, longer if you need to inspect a large dictionary before replacing anything.

The examples read and write files in your current directory and need no sudo. Keep the original list until the decompressed copy has passed your checks.

1. Check the installed command

Confirm which executable your shell will actually run, and record both the package and program versions. They are different pieces of information:

$ command -v prezip-bin
/usr/bin/prezip-bin
$ dpkg-query -W -f='${Package} ${Version}\n' aspell
aspell 0.60.8.1-1build1
$ prezip-bin -V
prezip, a prefix delta compressor. Version 0.1.1, 2004-11-06
  • -z compresses.
  • -d decompresses.
  • -V prints the version.

The manual notes it reads standard input and writes standard output, so shell redirection is the normal interface, not a workaround.

Checkpoint

Continue only if command -v found the executable you meant to use. If it found something else, read that installation's manual before putting the command into a script.

2. Prepare a sorted word list

prezip-bin is built for sorted word lists, not arbitrary text. Sort a copy, or generate the list as a pipeline. The locale matters here: LC_COLLATE=C gives a repeatable byte-oriented order instead of depending on the host's regional settings.

$ LC_COLLATE=C sort -u < words.txt > words.sorted.txt
$ sed -n '1,5p' words.sorted.txt
alpha
alpine
beta
delta
gamma

Trim leading and trailing blank spaces used only for formatting: the manual warns those spaces survive into the compressed output, so do not strip spaces that are actually part of the word data. Check the input now, before compression, not after:

$ test -s words.sorted.txt && echo 'non-empty input'
non-empty input
$ LC_COLLATE=C sort -c words.sorted.txt
$ printf 'input lines: '
$ wc -l < words.sorted.txt

sort -c exits successfully when the file is already ordered for the chosen locale. An empty word list may be a valid input for your workflow, but test -s makes an accidental empty file obvious before it turns into a small, plausible-looking binary.

3. Compress to a new binary file

Run prezip-bin -z with the list on standard input and a new path on standard output:

$ prezip-bin -z < words.sorted.txt > words.pz 2> words.pz.err
$ status=$?
$ printf 'prezip-bin exit: %s\n' "$status"
prezip-bin exit: 0
$ test ! -s words.pz.err && echo 'no diagnostics'
no diagnostics
$ wc -c words.sorted.txt words.pz
18 words.sorted.txt
19 words.pz
37 total

Byte counts here are only an example. A prezip file is not guaranteed to be smaller: the manual explicitly warns that unsuited input can grow. Treat a zero exit status as a successful encoding, then verify the contents by decompressing.

Safety boundary

> truncates an existing destination before the command starts. If words.pz already holds something you need, choose a new name such as words.pz.new and rename it only after verification. A failed command can otherwise leave a partial or empty replacement behind.

4. Restore the text list and compare it

Use -d to read the binary file and write the restored list to a separate path:

$ prezip-bin -d < words.pz > words.restored.txt
$ cmp --silent words.sorted.txt words.restored.txt
$ printf 'comparison exit: %s\n' "$?"
comparison exit: 0
$ wc -l words.sorted.txt words.restored.txt
 3 words.sorted.txt
 3 words.restored.txt
 6 total

cmp returns zero only when the files are byte-for-byte identical, which is the check that actually matters for a round trip. It will also catch a mismatched line ending or missing final newline.

There is no persistent configuration to undo here. To discard the generated files once you have checked them, remove only the explicit temporary paths you created:

$ rm -- words.pz words.pz.err words.restored.txt

That deletion is irreversible. Keep the files if they are part of a dictionary build, or if you have not yet checked the consumer that will read the compressed list.

5. Feed a restored list into Aspell

The documented use case is piping a decompressed word list into Aspell's master-dictionary builder. Give Aspell an explicit language; without one it tries to open an <unknown> language data file. Write the resulting dictionary to a deliberate path, and test without replacing an existing one:

$ prezip-bin -d < words.pz | aspell --lang=en create master ./words.rws
$ printf 'create exit: %s\n' "${PIPESTATUS[1]}"
create exit: 0
$ file ./words.rws
./words.rws: data

PIPESTATUS is a Bash array: element zero is prezip-bin, element one is aspell. Check both when a pipeline matters, because a shell can otherwise report only the last command's status:

$ prezip-bin -d < words.pz | aspell --lang=en create master ./words.rws
$ printf 'decompress=%s create=%s\n' "${PIPESTATUS[0]}" "${PIPESTATUS[1]}"
decompress=0 create=0

If the destination dictionary already exists, stop before running that command, or pick a new filename. Replacing a live dictionary can affect spelling checks for every program that uses it. Restore the previous file from your backup or package-managed copy rather than guessing at its contents.

Common traps

  • Missing command or bad option. Produces a non-zero status and a usage diagnostic.
  • Unrecognised input. The installed command reports unknown format for decompression when the input is not a recognised compressed word-list format:
$ prezip-bin -d < not-a-word-list.pz > restored.txt
unknown format
$ printf 'exit: %s, output bytes: ' "$?"
exit: 2, output bytes: 
$ wc -c < restored.txt
0

A file that begins plausibly but ends early can produce corrupt input or unexpected EOF instead. The manual warns corruption may leave some valid data in the output, so treat any non-zero status as a failed restore: write to a disposable or temporary destination, and do not replace a known-good list until both the status and the comparison pass.

For a script, capture the status directly and protect the previous output:

$ tmp='words.restored.txt.new'
$ if prezip-bin -d < words.pz > "$tmp"; then
>   cmp --silent words.sorted.txt "$tmp" && mv -- "$tmp" words.restored.txt
> else
>   printf '%s\n' 'decompression failed; old output was not changed' >&2
>   rm -- "$tmp"
> fi

The temporary file is removed on failure. The original restored file, if there was one, stays untouched.

Done means

  • Versions recorded. Executable, Aspell and prezip-bin versions are all confirmed.
  • Input is clean. The source list is sorted with a deliberate locale and has no accidental formatting spaces.
  • Compression succeeded. prezip-bin -z created a binary file without a diagnostic.
  • Round trip verified. prezip-bin -d returned zero and cmp confirmed an exact match.
  • Dictionary path is new. Any Aspell dictionary was written somewhere deliberate, not over an existing one.
  • Failures cannot clobber good output. A failed decompression never overwrites a known-good file.