EDITOR. This article and the eight
associated programs supplied on this
issue are only a very small part of a
large collection of
compression/decompression routines that
Steven submitted to 8BS.
I have compiled a disc containing the
full submission and placed it into the
TBI pool as TBI-102. A single sided DFS
disc.
by Steven Flintham (15A) Part 1 Introduction
This article describes a set of
utilities for compressing and
decompressing files using LZSS
compression.
Unlike the more common methods (run
length coding, for example) used on
the BBC LZSS compression will work
effectively on most files, including
saved screens, text and programs.
However it has its disadvantages.
Compressing a file requires a lot of
memory and is slow, so it is not
always practical. For example, an art
package might want to save screens in
a compressed form. This is possible
using simple run-length coding but
LZSS compression is too slow and
memory intensive.
A lot of the time this is not a
problem. If you want the title screen
of a game compressing, it doesn't
matter if it took a minute or two and
all the machine's memory to compress
it, as long as it decompresses quickly
when the game is loaded.
Similarly, you might want to compress
an archive produced by Chris
Richardson's Archiver before putting
it on a public domain disc or
uploading it to a bulletin board.
Everyone using it will want to
decompress it but it only needs to be
compressed once.
So LZSS compression is asymmetric -
compression is hard work but
decompression is quite easy. As long
as this isn't a problem these
utilities should be worth a look.
This article will not explain how LZSS
compression works, just how to use
these utilities. I hope to write
another article giving the technical
details in a later issue.
Warning Although I think these utilities are
fairly reliable there is still a
chance that they will corrupt or
destroy files when compressing or
decompressing. You are strongly
advised to take care when using them
and to have a backup of any important
data on the discs used.
In particular, just because a file
compresses correctly it does NOT mean
that it will decompress correctly. If
you intend to delete the original you
should decompress the compressed
version first as a test. It seems
unlikely but it may be possible that
even though a file decompresses
correctly once it may not do so at a
later date.
You should also bear in mind that if a
disc fault occurs in a compressed file
it will be almost impossible to
recover using a sector editor or
similar tool.
Compression
Files are compressed using the program
LZSSC. When you run it, it will pause
for a few seconds and then ask you for
the file to be compressed (the input
file). At this point you can remove
the disc containing LZSSC if you need
to as it will not be accessed again.
You can enter a * command instead of a
filename but you must include the * so
the program knows it's not a filename.
After giving the file to be compressed
you will be asked for the filename to
use for the compressed data (the
output file).
This should not be the same as the
previous filename - if it is you will
lose the original file as the program
cannot tell if the two are the same.
You will be warned if the output file
already exists.
Finally you are asked for the number
of offset and length bits to be used.
The minimum and maximum acceptable
values are shown. Changing these
values will affect the size of the
compressed data and you may want to
experiment with them. A good
'standard' setting is 11 offset bits
and 4 length bits although a smaller
number of offset bits may be more
suitable for short files.
The program will then compress the
file. As mentioned above this can take
some time so you are informed of
progress as it works. If the
information given doesn't make sense
you can just ignore it.
When it finishes it will tell you how
long it took, how fast it was working
and (most importantly) the compression
ratio. There is no standard meaning of
compression ratio - in this program a
compression ratio of 25% means the
compressed file is a quarter of the
size of the original file.
The compression ratio can be larger
than 100%, in which case the original
file gets larger when compressed (at
least for the particular number of
offset and length bits used, and
probably for all choices). It will
still decompress correctly but there's
no real point in keeping the
compressed version.
Finally you have the option to start
again and compress another file. Note
that except when compression is taking
place you can press ESCAPE to quit the
program.
Decompression
If you want to decompress a file so
that you have the original on disc
again you have two options, LZSSD and
LZSSDF.
You need not worry too much about
which one you choose as both will
produce the same result. However I
recommend using LZSSDF most of the
time as it is much faster. For very
large files it will not work but it
will tell you when this happens and
you can then use LZSSD instead.
Both programs are almost identical in
use so unless one of the programs is
mentioned specifically the following
instructions apply to both.
When you run the program after a short
pause you will be asked for the
filename of the compressed file (the
input file). As in LZSSC you can enter
a * command instead of a filename. The
program will check that the file you
specify is a compressed file.
You will then be asked for the
filename to use for the decompressed
file (the output file). As in LZSSC
you will be warned if there is already
a file with that name and you must not
use the same filename as the
compressed file.
You do not need to specify length or
offset bits for decompression as the
correct values are stored in the
compressed file so decompression will
then start. LZSSD will keep you
informed of progress but LZSSDF will
not. Both programs display the same
information as LZSSC once
decompression has finished.
Finally you have the option to
decompress another file. As in LZSSC
you can press ESCAPE to quit the
program at any time except during
decompression.
Press Space.