Menu

#539 Decompress .7z files

open
1
2024-03-06
2024-03-06
No

I'm currently working on my project development using IAR EWARM, with the STM32H573RI microcontroller and the FreeRTOS environment.

My task involves decompressing .7z files stored on an SD Card, which is interfaced with the microcontroller. To achieve this, I've utilized the LZMA C code provided in lzma\C\Util\7zMain.c for decompression. However, I've encountered an issue with SzArEx_Extract, where it attempts to create a memory buffer of the full size of the extracted file. This results in a "cannot allocate memory" error. For example, if the file size is 26 KB, it tries to allocate 26 KB of memory, leading to failure.

As you suggested using "CPP" files could help address such issues. Thus, I've begun implementing "CPP" by referring to CPP\7zip\Bundles\Format7zExtractR\makefile. However, I'm facing difficulties compiling these files due to numerous dependencies on Windows files and threads, which are incompatible with my environment. Upon inspecting "CPP\7zip\UI\Client7z\Client7z.cpp", I noticed the presence of NCOM interfaces from Windows. Could you provide guidance on how to avoid these dependencies and make the code better suited for my environment?

Thanks,
Prashanth

Discussion

  • oset jan

    oset jan - 2024-03-06

    One thing I don't get here, why would you use 7-zip on microcontroller. Microcontroller with 640 kB of RAM.
    7-zip uses big dictionaries (by default 16 MB), that don't fit into memory of your device. You will not be able to decompress it because your processor does not have enough memory.

    If I were you I would use Zip instead. It uses deflate by default, which uses 32 kB dictionary and had many, good libraries, with streaming implemented. That will easily fit into memory of your microcontroller. It may not by that tight compressor but it is good nevertheless.

     

    Last edit: oset jan 2024-03-06
  • Igor Pavlov

    Igor Pavlov - 2024-03-06

    C version of 7z decoder allocates for buffer for full uncompressed
    size of largest solid block.
    If your archives are small, then you can use 7zMan.c (C version) decoder, if have 600 KB of memory.

    C++ needs dictionary_size + lzma_state_size + some_buffers. But it's possible to reduce buffers. So if you have space for small dictionary in RAM, you can use C++ version. Use ST_MODE = 1 in makefile for single thread version.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.