diff --git a/firmware/mkwebfs.py b/firmware/mkwebfs.py index 0e3c0d3..39d5c14 100755 --- a/firmware/mkwebfs.py +++ b/firmware/mkwebfs.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 import os +import gzip incHttpHeader = True +useCompression = True fileDir = "fsdata/fs/" def dumpBin2CHex(f, b): @@ -58,9 +60,24 @@ for file in httpFiles: if(fext.endswith("ram")): ctype = b'Content-type: audio/x-pn-realaudio\r\n' response += ctype - response += b"\r\n" + binFile = open(file, 'rb') - response += binFile.read() + binData = binFile.read() + compEff = False + if useCompression: + compData = gzip.compress(binData, 9) + if len(compData) < len(binData): + compEff = True + print("- Compressed from {} to {}".format(len(binData), len(compData))) + binData = compData + else: + print("- Compression skipped Orig: {} Comp: {}".format(len(binData), len(compData))) + binFile.close() + + if compEff: + response += b'Content-Encoding: gzip\r\n' + response += b"\r\n" + response += binData binFile.close() escFile = file.replace("/", "_").replace(".", "_") escFileData = "data_" + escFile