Skip to content

Commit 34d6791

Browse files
authored
Merge pull request #467 from sVnsation/ota-gzip
compress firmware bin with gzip for ota
2 parents 0a5833e + f6f0552 commit 34d6791

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

scripts/getVersion.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import shutil
3+
import gzip
24
from datetime import date
35

46
def genOtaBin(path):
@@ -24,6 +26,11 @@ def genOtaBin(path):
2426
with open(path + "ota.bin", "wb") as f:
2527
f.write(bytearray(arr))
2628

29+
# write gzip firmware file
30+
def gzip_bin(bin_file, gzip_file):
31+
with open(bin_file,"rb") as fp:
32+
with gzip.open(gzip_file, "wb", compresslevel = 9) as f:
33+
shutil.copyfileobj(fp, f)
2734

2835
def readVersion(path, infile):
2936
f = open(path + infile, "r")
@@ -48,16 +55,19 @@ def readVersion(path, infile):
4855
src = path + ".pio/build/esp8266-release/firmware.bin"
4956
dst = path + "firmware/" + versionout
5057
os.rename(src, dst)
58+
gzip_bin(dst, dst + ".gz")
5159

5260
versionout = version[:-1] + "_esp8266_1m_" + sha + ".bin"
5361
src = path + ".pio/build/esp8285-release/firmware.bin"
5462
dst = path + "firmware/" + versionout
5563
os.rename(src, dst)
64+
gzip_bin(dst, dst + ".gz")
5665

5766
versionout = version[:-1] + "_esp32_" + sha + ".bin"
5867
src = path + ".pio/build/esp32-wroom32-release/firmware.bin"
5968
dst = path + "firmware/" + versionout
6069
os.rename(src, dst)
70+
gzip_bin(dst, dst + ".gz")
6171

6272
# other ESP32 bin files
6373
src = path + ".pio/build/esp32-wroom32-release/"

0 commit comments

Comments
 (0)