1234567891011121314151617181920212223242526272829303132333435 |
- #!/usr/bin/python3
-
- import os, gzip
- # https://www.mischianti.org/2020/10/26/web-server-with-esp8266-and-esp32-byte-array-gzipped-pages-and-spiffs-2/
-
- def convert_to_gzip(src, out, f):
- input_file = f'{src}{f}'
- output_file = f'{out}{f}.gz.h'
- output_charp = f'{f.replace(".", "_")}_gz'
-
- top = ''
- with open(input_file, 'rb') as f_in:
- gz = gzip.compress(f_in.read())
- gzlen = len(gz)
-
- top += f'// filename: {f}.gz.h\n'
- top += f'#define {output_charp}_len {gzlen}\n'
- top += f'const char {output_charp}[] = '
- top += '{'
-
- with open(output_file, 'wb') as f_out:
- for i, b in enumerate(gz):
- if not i%10:
- top += '\n '
- top += f'0x{b:02X}, '
- top = top[:-2]
- top += '};'
- f_out.write(top.encode(encoding='utf-8'))
-
-
- src='include/http/'
- out='include/'
-
- for f in os.listdir(src):
- convert_to_gzip(src, out, f)
|