-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decompress without Stream
class (passing data pointer and data size continuously)
#44
Comments
hey @hideakitai thanks for your very interesting feedback, If you have a code implementation in mind I'll be happy to review it and learn from it, but I have no idea how to achieve that without inheriting from the Stream class. However I understand your project uses BLE to receive compressed data, and I have a few questions:
|
Thank you for the reply :) Though it's just an idea, I think it's great if we can pass the data instead of the ESP32-targz/src/ESP32-targz-lib.cpp Lines 1037 to 1059 in dc8c8c3
All of them, if possible! (I will use gz and tar.gz)
About 10-15MB... I will use external 32MB SPI flash memory.
In this project, NO. (ESP32-WROOM-32D w/ Flash 4MB)
Reliability. Because BLE is slow, I don't want to send it again :) |
gz
So unless your BLE service has seek and readbytes characteristic (or a local gzReadHeader implementation) this method can't be applied on the fly. The other decompression method is tar.gztar.gz is a gzipped tar file, it can work:
Solution 1) ThoughtsIf you're limited in destination space, However, read and seek responsibilities depend on the relationship between the BLE peers during file transfer, for example if it's using notifications to send file chunks, there is no way the receiver can tell the notifier to "wait until the last chunk is uncompressed" while properly maintaining the buffer. On the other hand if the file chunks are sent as query responses, then it should also be possible to query for size, cursor position and specific file data chunk, and no buffer is really needed. Although both situations are out of scope with ESP32-Targz , they can still be solved by writing a class that inherits the Stream object. |
(In reply to tobozo's last comment) Hello,
I then make my HTTPS request for a gzipped website (asking for I think this may well be possible because Thank you, |
@ChaoticNeutralCzech GzUnpacker without stream is just raw uzlib. Here's a basic example of Be aware that accessing SPIFFS in RW mode while receiving HTTP response is known to produce bugs (crashes, data corruption). It will be more stable to store the decompressed data in psram or SD card, then copy the blob to the filesystem after the decompression is complete and the HTTP connection is closed. uzlib setupTINF_DATA decompress_nodict = {
.source = nullptr ,
.readSourceByte = yourByteReaderFunction, // reads one byte from gzipped data
.readDestByte = yourDestReaderFunction, // reads any byte in the decompressed data
.destSize = 1,
.readSourceErrors = 0,
};
uzlib_init();
res = uzlib_gzip_parse_header(&decompress_nodict);
if (res != TINF_OK) {
printf("[ERROR] uzlib_gzip_parse_header failed (response code %d)\n", res);
return;
}
uzlib_uncompress_init(&decompress_nodict, NULL, 0);
uzlib loop// const size_t output_buffer_size = 4096; // at least 1KB, at most 4KB
// uint8_t output_buffer[output_buffer_size]; // output buffer
size_t total_size = 0;
size_t output_position = 0;
int res = TINF_OK;
do {
decompress_nodict.dest = &output_buffer[output_position];
res = uzlib_uncompress_chksum(&decompress_nodict);
if (res != TINF_OK) break; // uncompress done or aborted, no need to go further
output_position++;
if (output_position == output_buffer_size) { // when destination buffer is filled, write/stream it
total_size += output_buffer_size;
printf("[INFO] Buffer full, now writing %d bytes (total=%d)\n", output_buffer_size, total_size);
write_buffer( output_buffer, output_buffer_size );
output_position = 0;
}
} while ( res == TINF_OK );
if (res != TINF_DONE) && decompress_nodict.readSourceErrors > 0 ) {
printf("Decompression failed with %d errors\n", decompress_nodict.readSourceErrors);
return;
}
// consume remaining bytes in the buffer, if any
if( output_position !=0 ) write_buffer(output_buffer, output_position );
|
Hi, thank you for the great library!
I would like to use this library with BLE. BLE does not inherit from the
Stream
class, so I can't feed data directly into this library. I think I need to save the received BLE packet asfs::File
once and then pass the file to this library.If there was an interface to the library that could continuously pass the data pointer and data size (passing
uint8_t* data, size_t size
likeesp_ota_write
function), I think this library could be applied more universally to data that doesn't inherit from theStream
class. Is there already such a way?I looked at the code of the library. If the "read data from the stream class and pass it to the decompressor" code could be split into a "read data from the stream class" part and a "pass data to the decompressor" part, it would be more versatile, including the above usage. I hope you like it. If you have any ideas or policies on how to implement this, I would be happy to help :) Thanks again for the great library!
The text was updated successfully, but these errors were encountered: