Extractor¶
-
class
tfsnippet.utils.Extractor(archive_file)¶ Bases:
objectThe base class for all archive extractors.
from tfsnippet.utils import Extractor, maybe_close with Extractor.open('a.zip') as archive_file: for name, f in archive_file: with maybe_close(f): # This file object may not be closeable, # thus we surround it by ``maybe_close()`` print('the content of {} is:'.format(name)) print(f.read())
Methods Summary
close()Close the extractor. iter_extract()Extract files from the archive with an iterator. open(file_path)Create an Extractorinstance for given archive file.Methods Documentation
-
close()¶ Close the extractor.
-
iter_extract()¶ Extract files from the archive with an iterator.
You may simply iterate over a
Extractorobject, which is same as calling to this method.Yields: (str, file-like) –
- Tuples of
(name, file-like object), the filename and corresponding file-like object for each file in the archive. The returned file-like object may or may not be closeable. You may surround it by
maybe_close().
- Tuples of
-