Chat freely about anything...

User avatar
By sfranzyshen
#9557 I am looking to embed a (base64) gzip file within a header (.h) file stored in an array to be sent out later to a client (browser) using the http protocol with the "Content-Encoding", "gzip" header set ...

-Should I use base64 ... or is there another method to encode gzip binary data into a header file?
-Is there a header to also tag the data as base64 ... or will I have to decode the base64 before sending data?
-are there any limits (besides the obvious ram/rom limits) for arrays to be concerned about
-does anyone have any similar code examples laying around?
-does anyone have a better idea of how to do this?

thanks ...
Last edited by sfranzyshen on Thu Feb 12, 2015 1:55 pm, edited 1 time in total.
User avatar
By lethe
#9565 You could simply convert a hexdump of your file to a char array, like:
Code: Select allchar file[] = { 0xDE, 0xAD, 0xBE, 0xEF };

This will of course make your header file larger, but you won't need to decode the file on the ESP and the file won't take more space than necessary on the ESPs flash.
User avatar
By sfranzyshen
#9569
lethe wrote:You could simply convert a hexdump of your file to a char array, like:
Code: Select allchar file[] = { 0xDE, 0xAD, 0xBE, 0xEF };

This will of course make your header file larger, but you won't need to decode the file on the ESP and the file won't take more space than necessary on the ESPs flash.

wouldn't I still need to do somekind of hex convertion on the data before I sent it to the browser?

ok here is what I am trying to do: (from unix)

gzip test.html
base64 test.html.gz > test.b64
echo "ICACHE_FLASH_ATTR char html[] = {" > tmp
cat test.b64 >> tmp
echo "}" >>tmp
mv tmp html.h

include the html.h into my program and send the data using the http protocol. I am hoping that I will not have to decode base64 on the esp8266 ... Instead pass it along to the (client) browser to handel ... using http1.1 headers we should be able to pass the data "as is" to the client using these http headers ...

Content-type: text/html
Content-encoding: gzip
Content-transfer-encoding: base64

However non of this has been fully tested ... YET! :o
User avatar
By lethe
#9573
sfranzyshen wrote:wouldn't I still need to do somekind of hex convertion on the data before I sent it to the browser?

No, the compiler will do this for you, since the hex chars are not quoted. The resulting program will have an array, which is a 1:1 representation of your file's content.

If you want to do more than to serve a single file, you should really have a look at esphttpd: viewtopic.php?f=6&t=376
It supports GET & POST requests, has a file system and a basic template system. A patch for gzip support is available here: viewtopic.php?f=6&t=376&start=190#p8645