.LZ

This file type is used by Nintendo in several games to compress files, resulting in reduced disk space.

New Super Mario Bros. Wii uses it to compress .rel files and cannot be used for anything else, whereas in Newer Super Mario Bros. Wii v1.30 it is commonly used to compress Wii U8 Archive files (.arc), Koopatlas Binary Worldmap files (.kpbin), and other binary files.

The compression algorithm is an invention by Lempel-Ziv (most famously known for LZ77/LZ78), which uses RLE ("Runtime-Length-Encoding") as compression method.

Important Advice: There are typical problems that arise when a user tries to save a custom level uncompressed in Newer Super Mario Bros. Wii, please see here: Usage in NewerSMBW.

=*.LZ (File Type)= Files with this file type are compressed files, they cannot be edited as-is. The extension  is added to the extension of the encapsulated file.

Some examples of this include:


 * (Relocatable Object file) becomes
 * (Wii U8 Archive) becomes
 * (Koopatlas Binary Worldmap file) becomes
 * (Binary file) becomes

Encode and Decode
Files can be encoded/compressed and decoded/decompressed to/from the .LZ file format by applying the correct algorithm to the data stream.

Please see Programs and Tools for available methods to decode and encode such files.

=Usage in NSMBW=  .LZ files take precedence over other files with the same name that do not have the .LZ extension. Therefore, if you decompress .rel files and leave them as-is, the game will load them just fine.

In New Super Mario Bros. Wii, only four files are compressed to the *.LZ format. Those are:

(Note: the folders are those found in a full dump of the game)


 * .rel (Relocatable Object file) files in

=Usage in NewerSMBW=  .LZ files take precedence over other files with the same name that do not have the .LZ extension. See next chapter (Compressed Assets in NewerSMBW) for more info.

In Newer Super Mario Bros. Wii, several additional files are compressed to the *.LZ format. Those are:

(Note: the folders are those found in the NewerSMBW Riivolution patch)


 * .arc (Wii U8 Archive) files in
 * (Backgrounds)
 * (Sprite model changes)
 * (Levels)
 * Some exceptions: (, folders ) are not compressed
 * .kpbin (Koopatlas Binary Worldmap file) files in
 * (Koopatlas worldmaps)
 * .bin (Binary file) files in
 * (Tilesets for Koopatlas worldmaps)
 * .bin (Binary file) files in
 * (Tilesets for Koopatlas worldmaps)

Compressed Assets in NewerSMBW
As we have learned above, LZ files take precedence over other files with the same name that do not have the LZ extension.

Let's do an example. We'll look at, which is the first level in the game. The following files with the same name exist in the  directory: The file with the .LZ extensions has priority and will be loaded by the game. The other file won't be loaded at all.
 * (compressed)
 * (compressed)
 * There are two options to play custom levels (or replace any other LZ-encoded assets):
 * 1) Encode the custom level/tileset/etc with a tool from Programs and Tools, and directly replace the  file.
 * 2) Delete the  file, and save your level/tileset/etc as   uncompressed, replacing the existing file. Consider backing up deleted files.


 * Examples for 2.
 * Delete
 * Save your custom model as
 * Delete
 * Save your custom level as
 * Delete
 * Save your custom background as

=Programs and Tools= Cue's DS/GBA Compressors can compress and decompress the LZ format (as well as others!). It is used by putting the file you wish to compress/decompress into the folder, and using either one of these two commands: Once done, the file will be LZ compressed, or decompressed depending on which one you use. Note that it doesn't automatically add/remove the *.LZ extension for you.

=Algorithm Details=

Lempel-Ziv
LZ77 and LZ78 are the two lossless data compression algorithms published in papers by Abraham Lempel and Jacob Ziv in 1977 and 1978. They are also known as LZ1 and LZ2 respectively. These two algorithms form the basis for many variations including Lempel–Ziv–Welch (LZW), Lempel-Ziv-Storer-Szymanski (LZSS), Lempel-Ziv-Markov chain algorithm (LZMA) and others. Besides their academic influence, these algorithms formed the basis of several ubiquitous compression schemes, including GIF and the DEFLATE algorithm used in Portable Network Graphics (PNG) and Zip (file format).

They are both theoretically dictionary coders. LZ77 maintains a sliding window during compression. This was later shown to be equivalent to the explicit dictionary constructed by LZ78&mdash;however, they are only equivalent when the entire data is intended to be decompressed.

Since LZ77 encodes and decodes from a sliding window over previously seen characters, decompression must always start at the beginning of the input. Conceptually, LZ78 decompression could allow random access to the input if the entire dictionary were known in advance. However, in practice the dictionary is created during encoding and decoding by creating a new phrase whenever a token is output.

Source: Wikipedia