def tarfile_with_unicode(tmpdir):
"""
Create a tarfile containing only a file whose name is
a zero byte file called testima?ge.png.
"""
tarobj = io.BytesIO()
with tarfile.open(fileobj=tarobj, mode="w:gz") as tgz:
data = b""
filename = "testima?ge.png"
if six.PY2:
filename = filename.decode('utf-8')
t = tarfile.TarInfo(filename)
t.size = len(data)
tgz.addfile(t, io.BytesIO(data))
target = tmpdir / 'unicode-pkg-1.0.tar.gz'
with open(str(target), mode='wb') as tf:
tf.write(tarobj.getvalue())
return str(target)
评论列表
文章目录