我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用zlib.Z_FINISH。
def compress_file(self): # stream-compress to another file then overwrite original self.file = open(self.filename, 'rb') compressed_filename = '%s.zlib' % self.filename compressed_file = open(compressed_filename, 'wb') compressor = zlib.compressobj(self.compression_level) compressed_file.write(struct.pack('>I', os.stat(self.filename).st_size)) data = self.file.read(READ_AMOUNT) while len(data) > 0: compressed_file.write(compressor.compress(data)) data = self.file.read(READ_AMOUNT) compressed_file.write(compressor.flush(zlib.Z_FINISH)) self.file.close() compressed_file.close() os.rename(compressed_filename, self.filename)
def flush(self, lib_mode=FLUSH): self._nltk_buffer.flush() GzipFile.flush(self, lib_mode)
def compress_and_finish(self, bytes): compressed_bytes = self._compress.compress(bytes) compressed_bytes += self._compress.flush(zlib.Z_FINISH) self._logger.debug('Compress input %r', bytes) self._logger.debug('Compress result %r', compressed_bytes) return compressed_bytes
def flush(self, lib_mode=FLUSH): self._buffer.flush() GzipFile.flush(self, lib_mode)