From 34f534bb24eb5063a829edb02ac2e21d2c117499 Mon Sep 17 00:00:00 2001 From: 2ndacc Date: Wed, 19 Feb 2020 21:04:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=8116byte=E5=88=86=E8=A1=8C?= =?UTF-8?q?=E5=92=8Cjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/http_server/test.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/TC1/http_server/test.py b/TC1/http_server/test.py index 84643f6..4f58e3d 100644 --- a/TC1/http_server/test.py +++ b/TC1/http_server/test.py @@ -4,12 +4,14 @@ import os import glob import binascii import gzip +import re + try: io = __import__("io").BytesIO except: io = __import__("StringIO").StringIO -for fn in glob.glob('*.html'): +def gen(fn): s = open(fn, 'rb').read() dat = io() with gzip.GzipFile(fileobj=dat, mode="w") as f: @@ -20,6 +22,13 @@ for fn in glob.glob('*.html'): except: s = ','.join(["0x"+binascii.hexlify(c) for c in dat]) - fn = fn.replace('.', '_') - print("const unsigned char %s[0x%x] = {%s};" % (fn, len(dat), s)) + s = re.sub("((?:0x.+?,){16})", "\\1\n", s) + fn = fn.replace('.', '_') + print("const unsigned char %s[0x%x] = {\n%s};" % (fn, len(dat), s)) + +for fn in glob.glob('*.html'): + gen(fn) + +for fn in glob.glob('*.js'): + gen(fn)