Python 3x-压缩使文件更大:( [英] Python 3x- Compression Makes File Bigger :(

查看:78
本文介绍了Python 3x-压缩使文件更大:(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的。最近,我正在为一个小项目测试一段代码。它需要我压缩一些文件,并且实际上会增大文件的大小,除非文件打印有问题。这是我的代码:

Ok. Recently I was testing out a piece of code for a small project. It required me to compress some files, and it actually makes the file size bigger, unless there is a problem in what it prints. Here's my code:

def Compress(z):
    #Line Spacing May Be Off A Little Because I'm New to Stack Overflow
    import zlib, sys, time, base64
    text = open(z, "rb").read()
    print ("Raw Size:", sys.getsizeof(text))
    compressed = zlib.compress(text, 9)
    print ("Compressed Size:", sys.getsizeof(compressed))
    ratio = sys.getsizeof(text) / sys.getsizeof(compressed)
    print ("Compression Ratio:", ratio)

编辑:嘿,谢谢您的回答,你们对我们有很大帮助!

Hey, thanks for answering, you guys were a lot of help!

推荐答案

并非所有输入都可以压缩。您的输入可能太短而无法压缩,或者可能根本没有模式或歪斜的统计信息供压缩器使用。压缩要求输入中具有某种形式的冗余以便进行压缩。

Not all inputs can be compressed. Your input might be too short to compress, or it might simply have no patterns or skewed statistics for the compressor to work with. Compression requires some form of redundancy in the input in order to compress.

这篇关于Python 3x-压缩使文件更大:(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆