本文整理汇总了Python中tarfile.RECORDSIZE属性的典型用法代码示例。如果您正苦于以下问题:Python tarfile.RECORDSIZE属性的具体用法?Python tarfile.RECORDSIZE怎么用?Python tarfile.RECORDSIZE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类tarfile
的用法示例。
在下文中一共展示了tarfile.RECORDSIZE属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stream_padding
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import RECORDSIZE [as 别名]
def test_stream_padding(self):
# Test for bug #1543303.
tar = tarfile.open(tmpname, self.mode)
tar.close()
if self.mode.endswith("gz"):
with gzip.GzipFile(tmpname) as fobj:
data = fobj.read()
elif self.mode.endswith("bz2"):
dec = bz2.BZ2Decompressor()
with open(tmpname, "rb") as fobj:
data = fobj.read()
data = dec.decompress(data)
self.assertTrue(len(dec.unused_data) == 0,
"found trailing data")
else:
with open(tmpname, "rb") as fobj:
data = fobj.read()
self.assertTrue(data.count("\0") == tarfile.RECORDSIZE,
"incorrect zero padding")
示例2: test_stream_padding
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import RECORDSIZE [as 别名]
def test_stream_padding(self):
# Test for bug #1543303.
tar = tarfile.open(tmpname, self.mode)
tar.close()
if self.mode.endswith("gz"):
fobj = gzip.GzipFile(tmpname)
data = fobj.read()
fobj.close()
elif self.mode.endswith("bz2"):
dec = bz2.BZ2Decompressor()
data = open(tmpname, "rb").read()
data = dec.decompress(data)
self.assertTrue(len(dec.unused_data) == 0,
"found trailing data")
else:
fobj = open(tmpname, "rb")
data = fobj.read()
fobj.close()
self.assertTrue(data.count("\0") == tarfile.RECORDSIZE,
"incorrect zero padding")
示例3: test_padding
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import RECORDSIZE [as 别名]
def test_padding(self):
self.dst.close()
if self.comp == "gz":
f = gzip.GzipFile(self.dstname)
s = f.read()
f.close()
elif self.comp == "bz2":
b = bz2.BZ2Decompressor()
f = file(self.dstname)
s = f.read()
f.close()
s = b.decompress(s)
self.assertEqual(len(f.unused_data), 0, "trailing data")
else:
f = file(self.dstname)
s = f.read()
f.close()
self.assertEqual(s.count("\0"), tarfile.RECORDSIZE,
"incorrect zero padding")
示例4: test_eof_marker
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import RECORDSIZE [as 别名]
def test_eof_marker(self):
# Make sure an end of archive marker is written (two zero blocks).
# tarfile insists on aligning archives to a 20 * 512 byte recordsize.
# So, we create an archive that has exactly 10240 bytes without the
# marker, and has 20480 bytes once the marker is written.
with tarfile.open(tmpname, self.mode) as tar:
t = tarfile.TarInfo("foo")
t.size = tarfile.RECORDSIZE - tarfile.BLOCKSIZE
tar.addfile(t, io.BytesIO(b"a" * t.size))
with self.open(tmpname, "rb") as fobj:
self.assertEqual(len(fobj.read()), tarfile.RECORDSIZE * 2)
示例5: test_stream_padding
# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import RECORDSIZE [as 别名]
def test_stream_padding(self):
# Test for bug #1543303.
tar = tarfile.open(tmpname, self.mode)
tar.close()
if self.decompressor:
dec = self.decompressor()
with open(tmpname, "rb") as fobj:
data = fobj.read()
data = dec.decompress(data)
self.assertFalse(dec.unused_data, "found trailing data")
else:
with self.open(tmpname) as fobj:
data = fobj.read()
self.assertEqual(data.count(b"\0"), tarfile.RECORDSIZE,
"incorrect zero padding")