本文整理匯總了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")