Content-Length: 266693 | pFad | http://github.com/micropython/micropython-lib/commit/f2217df5b27599674729134487b9c0f3aae0b103

51 tarfile: Make it possible to extract nested tarfiles in memory. · micropython/micropython-lib@f2217df · GitHub
Skip to content

Commit f2217df

Browse files
committed
tarfile: Make it possible to extract nested tarfiles in memory.
FileSection.skip() (see below the diff) uses 2-argument readinto, so attempting to recursively extract archives throws an error. This commit adds optional second argument to fix this problem. After this commit, it is possible to extract nested archives in roughly this fashion: with open(path, 'rb') as file: tar_outer = tarfile.TarFile(fileobj=file) for ti_outer in tar_outer: tar_inner = tarfile.TarFile( fileobj=tar_outer.extractfile(ti_outer)) for ti_inner in tar_inner: ... Nested archives are used in some embedded contexts, for example Mender artifacts. Signed-off-by: Wojciech Porczyk <wojciech.porczyk@connectpoint.pl>
1 parent f95568d commit f2217df

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

python-stdlib/tarfile/tarfile/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ def read(self, sz=65536):
4141
self.content_len -= sz
4242
return data
4343

44-
def readinto(self, buf):
44+
def readinto(self, buf, size=None):
4545
if self.content_len == 0:
4646
return 0
4747
if len(buf) > self.content_len:
4848
buf = memoryview(buf)[: self.content_len]
49+
if size is not None and len(buf) > size:
50+
buf = memoryview(buf)[:size]
4951
sz = self.f.readinto(buf)
5052
self.content_len -= sz
5153
return sz

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython-lib/commit/f2217df5b27599674729134487b9c0f3aae0b103

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy