Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python-stdlib/tarfile/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metadata(description="Read-only implementation of Python's tarfile.", version="0.4.1")
metadata(description="Read-only implementation of Python's tarfile.", version="0.4.2")

# Originally written by Paul Sokolovsky.

Expand Down
9 changes: 6 additions & 3 deletions python-stdlib/tarfile/tarfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ def skip(self):
if sz:
buf = bytearray(16)
while sz:
s = min(sz, 16)
self.f.readinto(buf, s)
sz -= s
if sz >= 16:
self.f.readinto(buf)
sz -= 16
else:
self.f.read(sz)
sz = 0


class TarInfo:
Expand Down
Binary file added python-stdlib/tarfile/test.tar
Binary file not shown.
45 changes: 45 additions & 0 deletions python-stdlib/tarfile/test_tarfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import tarfile
import unittest


test_tar_contents = (
("a", "file", 2),
("b", "file", 2),
("dir/", "dir", 0),
("dir/c", "file", 2),
("dir/d", "file", 2),
("tar.tar", "file", 10240),
)

test_sub_tar_contents = (
("e", "file", 2),
("f", "file", 2),
)


class TestTarFile(unittest.TestCase):
def check_contents(self, expected, tf):
for i, file in enumerate(tf):
name, type, size = expected[i]
self.assertEqual(file.name, name)
self.assertEqual(file.type, type)
self.assertEqual(file.size, size)

def test_iter(self):
tf = tarfile.TarFile("test.tar")
for _ in range(6):
self.assertIsInstance(next(tf), tarfile.TarInfo)
with self.assertRaises(StopIteration):
next(tf)

def test_contents(self):
tf = tarfile.TarFile("test.tar")
self.check_contents(test_tar_contents, tf)

def test_nested_tar(self):
tf = tarfile.TarFile("test.tar")
for file in tf:
if file.name == "tar.tar":
subf = tf.extractfile(file)
subtf = tarfile.TarFile(fileobj=subf)
self.check_contents(test_sub_tar_contents, subtf)
1 change: 1 addition & 0 deletions tools/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function ci_package_tests_run {
python-stdlib/pathlib \
python-stdlib/quopri \
python-stdlib/shutil \
python-stdlib/tarfile \
python-stdlib/tempfile \
python-stdlib/time \
python-stdlib/unittest/tests \
Expand Down
Loading