我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用tarfile.RECORDSIZE。
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(b"\0") == tarfile.RECORDSIZE, "incorrect zero padding")
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")
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() with open(tmpname, "rb") as fobj: data = fobj.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")
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")
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")