我正在创建一个zip文件,其中两个文件是用zlib压缩的,另外两个是未压缩的文件。当我试图解压相同的我得到下面的错误,其中一个压缩文件的内容被未压缩文件的内容覆盖。在
zipinfo 2019-08-14T13_21_59-症状报告.zip 存档:2019-08-14T13_21_59-症状报告.zip Zip文件大小:2378字节,条目数:4 ?rw-r--r--2.0 unx 21959 b-defN 2014年8月19日13:21症状报告/发行版/联网_信息输出日志 ?rw-r--r--2.0 unx 518 b-defN 2014年8月19日13:21症状报告/发行版/联网_信息执行日志 -rw-r--r--2.0 unx 140 b-stor 2014年8月19日13:21症状报告/元数据.yaml ?rw-------2.0 unx 1205 b-存储2014年8月19日13:21症状报告/执行.log 4个文件,23822字节未压缩,3534字节压缩:85.2%
解压缩2019-08-14T13_21_59-症状报告.zip 存档:2019-08-14T13_21_59-症状报告.zip 症状报告/发行版/联网信息/联网_信息输出:不匹配的“local”文件名(症状报告/元数据.yaml), 继续使用“中心”文件名版本 替换症状报告/发行版/联网信息/联网_info.output.log?[y] 是,[n]o,[A]ll,[n]一个[r]名称:
压缩文件作为流数据传递到zipfile,并使用zlib进行压缩。流数据是某些命令linux命令作为tar对象的输出。在
类ZipFile2(ZipFile):
"""Extends ZipFile so that it's possible to write files from stream input."""
def write_fp(self, fp, arcname, compress_type=ZIP_DEFLATED):
"""Put the bytes from filename into the archive under the name
arcname."""
if not self.fp:
raise RuntimeError('Attempt to write to ZIP archive that was already closed')
arcname = os.path.normpath(os.path.splitdrive(arcname)[1])
while arcname[0x00] in (os.sep, os.altsep):
arcname = arcname[1:]
zinfo = ZipInfo(arcname)
if compress_type is None:
zinfo.compress_type = self.compression
else:
zinfo.compress_type = compress_type
zinfo.file_size = 0x00
zinfo.flag_bits = 0x00
zinfo.external_attr = 0o644 << 16
zinfo.date_time = time.localtime(time.time())
zinfo.header_offset = self.fp.tell() # Start of header bytes
self._writecheck(zinfo)
self._didModify = True
if True:
# Must overwrite CRC and sizes with correct data later
zinfo.CRC = crc = 0x00
zinfo.compress_size = compress_size = 0x00
# Compressed size can be larger than uncompressed size
zip64 = self._allowZip64 and zinfo.file_size * 1.05 \
> ZIP64_LIMIT
self.fp.write(zinfo.FileHeader(zip64))
if zinfo.compress_type == ZIP_DEFLATED:
cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
zlib.DEFLATED, -15)
else:
cmpr = None
file_size = 0x00
while 1:
buf = fp.read(1024 * 8)
if not buf:
break
file_size = file_size + len(buf)
crc = zlib.crc32(buf, crc) & 0xffffffff
if cmpr:
buf = cmpr.compress(buf)
compress_size = compress_size + len(buf)
self.fp.write(buf)
if cmpr:
buf = cmpr.flush()
compress_size = compress_size + len(buf)
self.fp.write(buf)
zinfo.compress_size = compress_size
else:
zinfo.compress_size = file_size
zinfo.CRC = crc
zinfo.file_size = file_size
if not zip64 and self._allowZip64:
if file_size > ZIP64_LIMIT:
raise RuntimeError('File size has increased during compressing')
if compress_size > ZIP64_LIMIT:
raise RuntimeError('Compressed size larger than uncompressed size')
# Seek backwards and write file header (which will now include
# correct CRC and file sizes)
position = self.fp.tell() # Preserve current position in file
self.fp.seek(zinfo.header_offset, 0x00)
self.fp.write(zinfo.FileHeader(zip64))
self.fp.seek(position, 0x00)
self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo
我希望内容是正确的解压后不重写内容。在
目前没有回答
相关问题 更多 >
编程相关推荐