Added gzip compression
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
28cf59ee91
commit
8a9e1b6708
1 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue