ndspy.codeCompression: Code Compression

ndspy.codeCompression provides functions for the compression format used for executable code files.

This compression format is sometimes unofficially known as “BLZ” (“backwards LZ”). It’s essentially the same as LZ10 compression, except that the file is decompressed in reverse, beginning at the end of the file. This allows for in-place decompression on the console.

Note

If you’re using the ndspy.code module, compression is handled automatically for you, and you shouldn’t need to use this module explicitly.

See also

This module also includes a command-line interface.

ndspy.codeCompression.compress(data[, isArm9=False])[source]

Compress code data. This is the inverse of decompress().

Parameters:
  • data (bytes) – The data to compress.
  • isArm9 (bool) –

    Whether the data to be compressed is a main ARM9 code file or not. ARM9 code needs to be compressed slightly differently. (This should be False for overlays.)

    default:False
Returns:

The compressed data.

Return type:

bytes

ndspy.codeCompression.compressFromFile(filePath[, isArm9=False])[source]

Load a filesystem file, and compress its contents. This is the inverse of decompressToFile(), and is a convenience function.

Parameters:
  • filePath (str or other path-like object) – The path to the file to open.
  • isArm9 (bool) – Equivalent to the same parameter in the compress() function.
Returns:

The compressed data.

Return type:

bytes

ndspy.codeCompression.compressToFile(data, filePath[, isArm9=False])[source]

Compress data in the code compression format, and save it to a filesystem file. This is the inverse of decompressFromFile(), and is a convenience function.

Parameters:
  • data (bytes) – The data to compress.
  • filePath (str or other path-like object) – The path to the compressed file to save to.
  • isArm9 (bool) – Equivalent to the same parameter in the compress() function.
ndspy.codeCompression.decompress(data)[source]

Decompress data that was compressed using code compression. This is the inverse of compress().

If the data does not seem to be compressed, it will be returned unmodified.

Parameters:data (bytes) – The compressed data.
Returns:The decompressed data.
Return type:bytes
ndspy.codeCompression.decompressFromFile(filePath)[source]

Load a filesystem file that is compressed using code compression, and decompress it. This is the inverse of compressToFile(), and is a convenience function.

Parameters:filePath (str or other path-like object) – The path to the compressed file to open.
Returns:The decompressed data.
Return type:bytes
ndspy.codeCompression.decompressToFile(data, filePath)[source]

Decompress data that was compressed using code compression, and save it to a filesystem file. This is the inverse of compressFromFile(), and is a convenience function.

Parameters:
  • data (bytes) – The data to decompress.
  • filePath (str or other path-like object) – The path to the file to save to.
ndspy.codeCompression.main([args])[source]

This is the main function for this module’s command-line interface. This allows you to invoke the CLI programmatically, if you would like.

Parameters:args (list of str) – The command-line arguments. Defaults to sys.argv if not provided.