Struggling trying to make BrotliEncoderCompress on a ESP32 microprocessor #294

Closed
opened 2026-01-29 20:41:30 +00:00 by claunia · 1 comment
Owner

Originally created by @martinberlin on GitHub (Sep 30, 2019).

Hello I've forked some time ago this great library since I wanted to decompress incoming data in the ESP32. This worked great and it was the first mission trying Brotli.
It takes about 1 millisecond to decompress 26 bytes

Now I wanted to make the opposite example, to read a small file and try to use BrotliEncoderCompress and in this part is the one I'm failing:

https://github.com/martinberlin/brotli/blob/feature/compress/tests/src/main.cpp

Can you please provide a code snippet or working example using this method?
I guess it can be related to my failure that:

1.- The ESP32 needs time to do it's WiFi stuff, so it can be that is struggling with it
2.- Is using too much memory and cannot allocate enough (But I don't think that is the case)

1482 bytes read into inBuffer from: /144.txt
Calling BrotliEncoderCompress
Compression params:
2 quality
19 lgwinabort() was called at PC 0x40119c42 on core 1

The code is just opening a file and reading the bytes in a buffer. Maybe is easier to see here that I'm doing something wrong:

File file = SPIFFS.open(fileName, "r"); 
    fileSize = file.size();
    char *inFileBuffer = new char[fileSize];
    file.readBytes(inFileBuffer, fileSize);
    file.close();
    Serial.printf("%d bytes read into inBuffer: ", fileSize);

    int quality = 2; 
  int bufferSize = 40000;
  uint8_t *buffer = new uint8_t[bufferSize];
  size_t encodedSize = bufferSize;
  int lgwin = 22;

  
//***ERROR*** 19 lgwinabort() was called at PC 0x40119c42 on core 1

 BrotliEncoderCompress(
      quality,  
      lgwin, 
      BrotliEncoderMode::BROTLI_GENERIC,
      fileSize, 
      (const uint8_t *)inFileBuffer,     
      &encodedSize,
      buffer);

I will be very happy if I can make the compression part working in this internet of the things devices. Thanks in advance for any advice.

Originally created by @martinberlin on GitHub (Sep 30, 2019). Hello I've forked some time ago this great library since I wanted to decompress incoming data in the ESP32. This worked great and it was the first mission trying Brotli. It takes about 1 millisecond to decompress [26 bytes](https://twitter.com/martinfasani/status/1178628873904431105/photo/1) Now I wanted to make the opposite example, to read a small file and try to use BrotliEncoderCompress and in this part is the one I'm failing: https://github.com/martinberlin/brotli/blob/feature/compress/tests/src/main.cpp Can you please provide a code snippet or working example using this method? I guess it can be related to my failure that: 1.- The ESP32 needs time to do it's WiFi stuff, so it can be that is struggling with it 2.- Is using too much memory and cannot allocate enough (But I don't think that is the case) ``` 1482 bytes read into inBuffer from: /144.txt Calling BrotliEncoderCompress Compression params: 2 quality 19 lgwinabort() was called at PC 0x40119c42 on core 1 ``` The code is just opening a file and reading the bytes in a buffer. Maybe is easier to see here that I'm doing something wrong: ```c File file = SPIFFS.open(fileName, "r"); fileSize = file.size(); char *inFileBuffer = new char[fileSize]; file.readBytes(inFileBuffer, fileSize); file.close(); Serial.printf("%d bytes read into inBuffer: ", fileSize); int quality = 2; int bufferSize = 40000; uint8_t *buffer = new uint8_t[bufferSize]; size_t encodedSize = bufferSize; int lgwin = 22; //***ERROR*** 19 lgwinabort() was called at PC 0x40119c42 on core 1 BrotliEncoderCompress( quality, lgwin, BrotliEncoderMode::BROTLI_GENERIC, fileSize, (const uint8_t *)inFileBuffer, &encodedSize, buffer); ``` I will be very happy if I can make the compression part working in this internet of the things devices. Thanks in advance for any advice.
Author
Owner

@martinberlin commented on GitHub (Oct 5, 2019):

Is working!
https://github.com/martinberlin/brotli/tree/feature/compress

If you have a recommendation in how to make the quality major than 1 I will be very happy. Just feel free to close this issue. Thank you very much for this great library.

@martinberlin commented on GitHub (Oct 5, 2019): Is working! https://github.com/martinberlin/brotli/tree/feature/compress If you have a recommendation in how to make the quality major than 1 I will be very happy. Just feel free to close this issue. Thank you very much for this great library.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#294