LHA

From Just Solve the File Format Problem
(Difference between revisions)
Jump to: navigation, search
(Edits due to new LArc article)
Line 1: Line 1:
 
{{FormatInfo
 
{{FormatInfo
 
|subcat=Archiving
 
|subcat=Archiving
|extensions={{ext|lha}}, {{ext|lzh}}, {{ext|lzs}}
+
|extensions={{ext|lha}}, {{ext|lzh}}
 
|mimetypes={{mimetype|application/x-lzh-compressed}}
 
|mimetypes={{mimetype|application/x-lzh-compressed}}
 
|pronom={{PRONOM|fmt/626}}
 
|pronom={{PRONOM|fmt/626}}
Line 16: Line 16:
 
The file format is also known as '''LZH'''. See the [[LZH|LZH disambiguation page]] for other "LZH" formats.
 
The file format is also known as '''LZH'''. See the [[LZH|LZH disambiguation page]] for other "LZH" formats.
  
This article covers the format used by LHarc/LHA, as well as "generalized" LHA format: the same file format, but with other compression schemes. The generalized format was possibly designed by Kazuhiko Miki in 1988 for the LArc software, but confirmation of this is needed. If so, it was soon borrowed by LHarc, with new compression schemes.
+
This article covers the format used by LHarc/LHA, as well as "generalized" LHA format: the same file format, but with other compression schemes. The generalized format was possibly designed by Kazuhiko Miki in 1988 for [[LArc]], but confirmation of this is needed. If so, it was soon borrowed by LHarc, with new compression schemes.
  
 
== Format details ==
 
== Format details ==
Line 72: Line 72:
 
|<code>-lx1-</code> ||  
 
|<code>-lx1-</code> ||  
 
|-
 
|-
|<code>-lz2-</code> ||rowspan="7"| LArc methods ||  
+
|<code>-lz2-</code> ||rowspan="7"| LArc methods ||rowspan="7"| Refer to [[LArc]].
 
|-
 
|-
|<code>-lz3-</code> ||
+
|<code>-lz3-</code>
 
|-
 
|-
|<code>-lz4-</code> || Uncompressed
+
|<code>-lz4-</code>
 
|-
 
|-
|<code>-lz5-</code> || LZ77/[[LZSS]], 4k window. Almost identical to "SZDD" used in [[MS-DOS installation compression]].
+
|<code>-lz5-</code>
 
|-
 
|-
|<code>-lz7-</code> ||
+
|<code>-lz7-</code>
 
|-
 
|-
|<code>-lz8-</code> ||
+
|<code>-lz8-</code>
 
|-
 
|-
|<code>-lzs-</code> || LZ77/[[LZSS]], 2k window
+
|<code>-lzs-</code>
 
|-
 
|-
 
|<code>-pc1-</code> ||rowspan="4"| PMarc extensions ||rowspan="4"| Refer to [[PMA]].
 
|<code>-pc1-</code> ||rowspan="4"| PMarc extensions ||rowspan="4"| Refer to [[PMA]].
Line 198: Line 198:
 
*** {{CdTextfiles|simtel/simtel20/MSDOS/ARCHIVRS/LHA211SR.ZIP|v2.11}}
 
*** {{CdTextfiles|simtel/simtel20/MSDOS/ARCHIVRS/LHA211SR.ZIP|v2.11}}
 
** Various versions at old-dos.ru: [http://old-dos.ru/index.php?page=files&mode=files&do=show&id=3432 LHarc], [http://old-dos.ru/index.php?page=files&mode=files&do=show&id=713 LHA], [http://old-dos.ru/index.php?page=files&mode=files&do=show&id=2836 LHA32]
 
** Various versions at old-dos.ru: [http://old-dos.ru/index.php?page=files&mode=files&do=show&id=3432 LHarc], [http://old-dos.ru/index.php?page=files&mode=files&do=show&id=713 LHA], [http://old-dos.ru/index.php?page=files&mode=files&do=show&id=2836 LHA32]
* [http://www.manmrk.net/tutorials/compress/downloads/larc333.exe LArc v3.33] (1989-05-19) (DOS software)
 
 
* LZHUF.C - Source code related to "lh1" compression
 
* LZHUF.C - Source code related to "lh1" compression
 
** {{CdTextfiles|powerprogramming/PROGTOOL/COMPRESS/LZHSRC10.ZIP|LZHSRC10.ZIP}} - "LZHUF.C English version 1.0 /  Based on Japanese version 29-NOV-1988 / LZSS coded by Haruhiko OKUMURA / Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI / Edited and translated to English by Kenji RIKITAKE"
 
** {{CdTextfiles|powerprogramming/PROGTOOL/COMPRESS/LZHSRC10.ZIP|LZHSRC10.ZIP}} - "LZHUF.C English version 1.0 /  Based on Japanese version 29-NOV-1988 / LZSS coded by Haruhiko OKUMURA / Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI / Edited and translated to English by Kenji RIKITAKE"

Revision as of 14:54, 25 April 2021

File Format
Name LHA
Ontology
Extension(s) .lha, .lzh
MIME Type(s) application/x-lzh-compressed
PRONOM fmt/626
Wikidata ID Q368782
Kaitai Struct Spec lzh.ksy
Released 1988

LHA is an archiving program and file format created by Haruyasu Yoshizaki (a.k.a. Yoshi) in 1988. It was originally called LHarc, then was briefly LH before settling on LHA. In the 1990s, it was the most popular archiving format on the Amiga platform. It also got some use on the PC platform including in the installers for id Software games such as Doom and Quake, because ZIP compression was inferior until the release of PKZIP 2.0, which brought the formats to parity.

It was particularly popular in Japan. Most of the best information about it is in Japanese.

It supports a number of different compression schemes, most of which use LZ77 combined with Huffman coding.

The file format is also known as LZH. See the LZH disambiguation page for other "LZH" formats.

This article covers the format used by LHarc/LHA, as well as "generalized" LHA format: the same file format, but with other compression schemes. The generalized format was possibly designed by Kazuhiko Miki in 1988 for LArc, but confirmation of this is needed. If so, it was soon borrowed by LHarc, with new compression schemes.

Contents

Format details

File structure

An LHA file consists mainly of a sequence of elements, each representing a member file or directory. The sequence is usually terminated by an end-of-archive marker consisting of a single 0x00 byte (but take care, as level 2 headers could start with 0x00). There is no global archive-level header.

Member format

There are at least four different formats that an element can have. (Note that this is independent of compression schemes.) In LHA jargon, the formats are known as "header levels", and are usually called "header level 0", "... 1", "... 2", and "... 3". The header level is determined by the byte at offset 20 from the beginning of that element.

The header levels are similar, but irritatingly different. They don't even follow the same principles with respect to how they must be parsed.

LZH compression overview

From a decompression perspective, the LZ77+Huffman schemes work roughly as follows. (This is oversimplified.) There is a codes Huffman tree, and a separate offsets tree. A symbol is read using the codes tree which, depending on its value, represents either a literal byte value, or a length. If it is a length, then an additional symbol is read using the offsets tree. Based on the offset and length, a run of recently-decompressed bytes is repeated.

Compression schemes

Each member file has a 5-byte compression method field, composed of ASCII characters. The first and last characters are virtually always dashes ("-"), and might be left off when discussing LHA compression schemes. Known schemes:

ID Category Description and remarks
-lh0- Uncompressed
-lh1- LZ77+Huffman, 4k window, adaptive Huffman for codes, offsets use a pre-defined Huffman tree.
-lh2- LZ77+Huffman, 8k window, adaptive Huffman. Considered obsolete.
-lh3- LZ77+Huffman, 8k window, segmented, static Huffman for codes, offsets can use static Huffman or a pre-defined Huffman tree. Considered obsolete.
-lh4- Like lh5, but 4k window. Rare.
-lh5- LZ77+Huffman, 8k window, segmented, static Huffman
-lh6- Like lh5, but 32k window
-lh7- Like lh5, but 64k window
-lh7- LHARK extension Refer to LHARK.
-lh8- Joe Jared extensions Like lh5, but 64k window. (Same as lh7.)
-lh9- Like lh5, but 128k window. Probably never used.
-lha- Like lh5, but 256k window. Probably never used.
-lhb- Like lh5, but 512k window. Probably never used.
-lhc- Like lh5, but 1M window. Probably never used.
-lhd- Special Not a compression scheme. Indicates that the element represents a subdirectory.
-lhe- Joe Jared extensions Like lh5, but 2M window. Probably never used.
-lhx- UNLHA32 extensions
-lx1-
-lz2- LArc methods Refer to LArc.
-lz3-
-lz4-
-lz5-
-lz7-
-lz8-
-lzs-
-pc1- PMarc extensions Refer to PMA.
-pm0-
-pm1-
-pm2-
-ah0- MAR extensions Refer to Micrognosis Compression Archiver.
-ari-
-hf0-
-lZ0- PUT/GET variants Refer to PUT.
-lZ1-
-lZ5-
␠LH0␠ SAR variants Refer to SAR (Streamline Design). The compression IDs begin and end with a space (0x20).
␠LH5␠

The Wikipedia article has more information about some of the schemes.

For reference, here are some other LHA-like identifiers:

ID References and remarks
-arn- Possibly used by Micrognosis Compression Archiver.
-lzw-
-LD6- Refer to LDIFF LZD.
-pms- Refer to PMA.
-sqx- Refer to SQX.
-sw0- Refer to SWG.
-sw1-
-TK1- Unknown. (Recognized by IDArc.)

Extended headers

For header levels 1 and higher, each member file has an associated list of "extended headers", similar to ZIP's extensible data fields. Each extended header is tagged with a single byte indicating its type. Extended headers are used to store platform-specific metadata, and to extend the format in other ways.

Header level 0 supports extended data in a more limited way. It allows for just one set of extended header fields (called the "extended area"), the content of which is determined by the initial one-byte "OS type" field.

Identification

LHA can be identified with high accuracy, but doing so can be laborious, due to the lack of a signature, and other complicating factors.

Identification logic could be based on the header of the first member file. Check that the compression method (offset 2–6) and header level (offset 20) fields have valid values. When suitable and possible, validate the header checksum field -- this depends on the header level.

See also the "#See also" section, for some formats that could masquerade as LHA.

See also

Other LHA-like formats to be aware of:

Format documentation

Software

Sample files

Other links

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox