我有以下代码:
import zlib
import os
...
for current, subs, files in os.walk('.'):
for filename in files:
# in format ##/#{38}
path = os.path.join(current, filename)[2:]
# 'info/' and 'pack/' exist
# don't worry about packed files
# assume empty (excluding . and ..)
with open(path, 'r') as file:
# returns bytes object
# assuming UTF-8 encoding (default) vs. legacy
# https://git-scm.com/docs/git-commit#_discussion
# .decode() also defaults to utf-8
print(zlib.decompress(file.read()).decode())
当前目录是
.git/objects/
,我收到以下错误:
print(zlib.decompress(file.read()).decode())
^^^^^^^^^^^
File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 8: invalid start byte
我试图分析的
.git
目录没有指定替代编码方法。