Added gzip compression
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
7m9 2021-09-09 02:35:15 +02:00
parent 28cf59ee91
commit 8a9e1b6708

View file

@ -1,7 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import gzip
incHttpHeader = True incHttpHeader = True
useCompression = True
fileDir = "fsdata/fs/" fileDir = "fsdata/fs/"
def dumpBin2CHex(f, b): def dumpBin2CHex(f, b):
@ -58,9 +60,24 @@ for file in httpFiles:
if(fext.endswith("ram")): if(fext.endswith("ram")):
ctype = b'Content-type: audio/x-pn-realaudio\r\n' ctype = b'Content-type: audio/x-pn-realaudio\r\n'
response += ctype response += ctype
response += b"\r\n"
binFile = open(file, 'rb') 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() binFile.close()
escFile = file.replace("/", "_").replace(".", "_") escFile = file.replace("/", "_").replace(".", "_")
escFileData = "data_" + escFile escFileData = "data_" + escFile