SQ (short for "squeeze") is a file compression [[computer program|program]] devised by Richard (Dick) Greenlaw circa 1981. It was used in the early 1980s on [[CP/M]] and [[MS-DOS]] systems, and was also ported to [[Unix]] and other platforms, to compress individual files so that they occupy less storage space. A companion utility, USQ (unsqueeze), is required to decompress a file back to its original form.
Operation
SQ performs compression in two stages:
- Run-length encoding — strings of identical bytes are collapsed into a delimiter-plus-count representation. A run of more than two identical bytes is replaced by the byte value, the delimiter, and the count; occurrences of the delimiter itself are escaped by following it with a zero count.
- Static Huffman coding — a frequency analysis pass is performed over the output of the run-length encoder, and the resulting byte distribution is encoded with a Huffman tree. Because the algorithm requires a full frequency pass before encoding begins, the process needs two passes over the complete file and is therefore unsuited to streaming.
Huffman code lengths are bounded so that no symbol exceeds 16 bits. The compressed file carries a checksum for integrity verification but does not store the length of the original data, so the uncompressed size becomes known only after decompression. Typical compression rates for text files were reported in the range of roughly 30 to 50 percent; small files or files with uniformly distributed byte values could grow slightly in size.
File naming and format
Files processed by SQ under CP/M and MS-DOS were identified by substituting the letter "Q" into the middle of the filename extension, so that text files acquired the extension .TQT, executable files .CQM or .EQE, documents .DQC, and batch files .BQT. On Unix-style systems the suffix .SQ was appended to the filename instead. Apple II ports (SQ3/USQ2, written by Don Elton) appended .QQ.
The standalone file format begins with a two-byte magic number ($76 $FF), a two-byte checksum, and a null-terminated ASCII string holding the original filename (which may include a full path). This is followed by a count of tree nodes and the nodes themselves, four bytes each (16-bit left and right child references), and finally the compressed data. Node references are stored as indices into the node array; child values are positive when pointing to an interior node and negative when denoting a literal byte value, offset by one. End-of-file is represented by the code value 256. All multi-byte values are stored in little-endian order. When the format is embedded within a NuFX archive, the header is omitted.
Adoption and decline
Groups of files were commonly bundled into an archive using the LU program, which produced .LBR files (an early [[archive format]]). Because LU performed no compression, the files within an LBR archive were either compressed individually with SQ beforehand, or the finished archive was itself compressed with SQ — a usage comparable to the later combination of [[tar (computing)|tar]] with a separate compressor.
With the arrival of the ARC program (which combined compression and archiving in a single tool and its own archive format), SQ became largely obsolete on most systems. It persisted longer on CP/M, where an ARC port was unavailable for several years; the CRUNCH program, implementing the [[LZW]] algorithm used by ARC, was written to fill that gap. The original SQ/USQ [[source code]] was released into the [[public domain]] and has since been redistributed and ported, including to modern C compilers and the [[z88dk]] toolkit.
See also
- [[Huffman coding]]
- [[Run-length encoding]]
- [[LZW]]
- [[Archive format]]
Notes
Other unrelated software has also used the short name "SQ," including a later open-source command-line data-wrangling tool, and the SQ designation used in some audio hardware and database product lines. These are distinct from the compression program described here.