Spaces:
Running
Running
Download quanxue-src/scripts/quanxue/escape_ctrl.py from Ethscriptions/mx: direct link, hf CLI and curl.
- Browser
- Download file 871 Bytes
-
https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/quanxue-src/scripts/quanxue/escape_ctrl.py
- Command line
-
hf download hf://spaces/Ethscriptions/mx/quanxue-src/scripts/quanxue/escape_ctrl.py
-
curl -L -o escape_ctrl.py https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/quanxue-src/scripts/quanxue/escape_ctrl.py
871 Bytes
| """把构建产物 JS 中字符串字面量里的原始控制字符转义为 \\xHH,使文件成为纯文本(避免被 Hub 识别为二进制而走 LFS/CDN 重定向)""" | |
| import sys, glob | |
| for path in sys.argv[1:]: | |
| for f in glob.glob(path): | |
| d = open(f, 'rb').read() | |
| out = bytearray(); i = 0; n = 0 | |
| while i < len(d): | |
| b = d[i] | |
| if b < 32 and b not in (9, 10, 13): | |
| # 统计前面的反斜杠:奇数个说明是 "\<控制字符>" 的恒等转义,去掉那个反斜杠 | |
| k = len(out); bs = 0 | |
| while k > 0 and out[k - 1] == 92: bs += 1; k -= 1 | |
| if bs % 2 == 1: out.pop() | |
| out += b'\\x%02x' % b; n += 1 | |
| else: | |
| out.append(b) | |
| i += 1 | |
| if n: | |
| open(f, 'wb').write(out); print(f, 'escaped', n) | |