Python zipfile.ZIP_BZIP2 Examples
The following are 2
code examples of zipfile.ZIP_BZIP2().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
zipfile
, or try the search function
.
Example #1
Source File: file.py From dffml with MIT License | 5 votes |
def zip_closer_helper(self): with zipfile.ZipFile( self.config.filename, self.WRITEMODE, compression=zipfile.ZIP_BZIP2 ) as archive: with archive.open( self.__class__.__qualname__, mode=self.WRITEMODE, force_zip64=True, ) as zip_fd: with io.TextIOWrapper(zip_fd, write_through=True) as fd: yield fd
Example #2
Source File: util.py From ShapeWorld with MIT License | 4 votes |
def __init__(self, path, mode, archive=None): assert mode == 'r' or mode == 'w' assert archive in (None, 'zip', 'zip:none', 'zip:deflate', 'zip:bzip2', 'zip:lzma', 'tar', 'tar:none', 'tar:gzip', 'tar:bzip2', 'tar:lzma') self.archive = path self.mode = mode if not os.path.isdir(self.archive[:self.archive.rindex('/')]): os.mkdir(self.archive[:self.archive.rindex('/')]) try: if not os.path.isdir('/tmp/shapeworld'): os.makedirs('/tmp/shapeworld') self.temp_directory = os.path.join('/tmp/shapeworld', 'temp-' + str(time.time())) os.mkdir(self.temp_directory) except PermissionError: self.temp_directory = os.path.join(self.archive[:self.archive.rindex('/')], 'temp-' + str(time.time())) os.mkdir(self.temp_directory) if archive is None: self.archive_type = None if not os.path.isdir(self.archive): os.mkdir(self.archive) elif archive[:3] == 'zip': self.archive_type = 'zip' if len(archive) == 3: compression = zipfile.ZIP_DEFLATED elif archive[4:] == 'none': compression = zipfile.ZIP_STORED elif archive[4:] == 'deflate': compression = zipfile.ZIP_DEFLATED elif archive[4:] == 'bzip2': compression = zipfile.ZIP_BZIP2 elif archive[4:] == 'lzma': compression = zipfile.ZIP_LZMA if not self.archive.endswith('.zip'): self.archive += '.zip' self.archive = zipfile.ZipFile(self.archive, mode, compression) elif archive[:3] == 'tar': self.archive_type = 'tar' if len(archive) == 3: mode += ':gz' extension = '.gz' elif archive[4:] == 'none': extension = '' elif archive[4:] == 'gzip': mode += ':gz' extension = '.gz' elif archive[4:] == 'bzip2': mode += ':bz2' extension = '.bz2' elif archive[4:] == 'lzma': mode += ':xz' extension = '.lzma' if not self.archive.endswith('.tar' + extension): self.archive += '.tar' + extension self.archive = tarfile.open(self.archive, mode)