首页 > 编程问答 >如何重新压缩该文件以匹配原始文件?

如何重新压缩该文件以匹配原始文件?

时间:2024-07-28 09:13:48浏览次数:8  
标签:python compression

我正在使用 WindLDR 来生成 PLC 梯形图。文件保存为 file_name.pjw 我写了一个 python 脚本来解压缩 pjw 文件,但现在我想重新压缩它们。然而,文件输出有所不同,我不确定如何解决这个问题。 这就是原始压缩文件格式的显示方式 从 linux 文件实用程序:

$ file project01OG.pjw 
project01OG.pjw: gzip compressed data, from TOPS/20, original size modulo 2^32 314621

压缩脚本生成:

$ file project01.pjw 
project01.pjw: gzip compressed data, was "project01.pjw", max compression, original size modulo 2^32 314621

这很相似,但缺少有关 TOPS/20 的位。 解压缩脚本:

#!/usr/bin/env python3
import gzip
import shutil

input_file = 'project01.pjw'
output_file = 'project01'

with gzip.open(input_file, 'rb') as f_in:
    with open(output_file, 'wb') as f_out:
        shutil.copyfileobj(f_in, f_out)

压缩脚本:

#!/usr/bin/env python3
import gzip
import shutil
input_file = 'project01'
output_file = 'project01.pjw'


with open(input_file, 'rb') as f_in:
    with gzip.GzipFile(output_file, 'wb', mtime=0) as f_out:
        shutil.copyfileobj(f_in, f_out)

所以我不确定如何实现 TOPS/20 位的压缩。

我尝试询问 ChatGPT,但它说类似编辑生成的文件输出在十六进制编辑器中,所以...我不会这样做。

我可以链接到 pjw 文件,或者解压缩的文件输出(如果有帮助的话)。


The "from TOPS/20" message in the file utility output doesn't actually indicate a different compression method. It's simply metadata embedded within the gzip header, a remnant of the file's origin on the TOPS/20 operating system.

The crucial part is that your Python script is already compressing the file correctly . The difference in the file output doesn't affect the actual decompression or the file's integrity.

Here's why you can be confident:

  1. gzip Compatibility: The gzip library in Python inherently follows the gzip standard. You're not modifying the compression algorithm itself.
  2. Identical Decompressed Data: If you decompress both the original and your re-compressed files, you'll find the content is identical.
  3. "Modulo 2^32" Significance: The "original size modulo 2^32" value matching in both file outputs confirms that the uncompressed data size is the same.

In conclusion, don't worry about the "from TOPS/20" message. Your Python scripts are working correctly, and the re-compressed files are functionally equivalent to the original.

If you're still concerned, you can verify the integrity of your process by:

  1. Checksum Comparison: Calculate the checksum (e.g., MD5, SHA-256) of the original compressed file and your recompressed file. If they match, the files are identical.
  2. Testing with WindLDR: The most important test is whether WindLDR can successfully open and use your recompressed .pjw files.

标签:python,compression
From: 78802769

相关文章

  • Python Beautiful Soup 不加载表值
    我是美丽汤的新手,不确定如何从该网站为每个州(新南威尔士州、维多利亚州、昆士兰州、南澳大利亚州)添加“解决”栏:https://www.asxenergy.com.au/futures_au似乎没有显示数值数据。我的起始代码是:frombs4importBeautifulSoupfromurllib.requestimportur......
  • c语言模拟Python的命名参数
    最近在书里看到的,让c语言去模拟其他语言里有的命名函数参数。觉得比较有意思所以记录一下。目标众所周知c语言里是没有命名函数参数这种东西的,形式参数虽然有自己的名字,但传递的时候并不能通过这个名字来指定参数的值。而支持命名参数的语言,比如python里,我们能让代码达到这种效......
  • 乌尔都语 Tts 可与 python 一起使用
    我想为乌尔都语创建TTS有什么帮助吗?我发现很少有模特拥抱着脸TheUpperCaseGuy/Guy-Urdu-TTSpocketmonkey/speecht5_tts_urduTalha185/speecht5_finetuned_urdu_TTS但我无法从文本创建或生成高质量的语音任何人都可以帮忙吗???importtorchfromtransformersimp......
  • 有没有办法在Python中使用OpenCV在边界框后面画一条线?
    我正在为我的本科论文编写一个应用程序,该应用程序从根本上允许使用OpenCV库跟踪视频源中的多个对象。为了进一步发展这个想法,我希望能够在屏幕上画一条线,显示边界框在我正在跟踪的对象周围的历史记录。我注意到没有排序用于执行此操作的内置函数,因此任何有关制作此类内容的......
  • 如何向 python pandas 数据透视表添加过滤器? (pd.read_excel)
    我正在尝试使用pandas库在python中重新创建我在Excel中制作的数据透视表。我试图用时间段作为过滤器来总结超过500k行的OD总行程数据。在Excel上,我只会执行行(O)、列(D)、值(行程)、过滤器(时间)。到目前为止,在python上我只有索引、列、值、aggfunc,但我不知道如何过滤。有......
  • 标量添加中的 Python 溢出警告
    我想执行一个简单的操作:b+g+rb,g,r变量是整数并且值低于256。我收到溢出警告和错误的结果。问题是操作很简单(结果不高于765),我不应该收到溢出警告这是我的代码:importcv2ascvimportnumpyasnpimgname='r_hh_classic.png'img=cv.imread(imgname)h,w,_=......
  • 在 Python 中读取部分 MP3 文件时处理“对于可用位计数来说太大”错误
    我正在尝试读取MP3文件的特定部分,但遇到错误:[src/libmpg123/layer3.c:INT123_do_layer3():1771]error:part2_3_length(1376)toolargeforavailablebitcount(760)可以访问音频文件此处我的环境是使用此Docker映像设置的:pytorc......
  • Python SQLAlchemy 2.0 使用 dataclass_transform 非必需字段类型
    我刚刚在一个新项目上安装了SQLAlchemy2.0,我正在尝试使我的模型尽可能类型安全。通过使用@typing_extensions.dataclass_transform,我已经能够实现我想要实现的大部分目标类型检查,但是当前所有字段都被标记为不需要。例如:@typing_extensions.dataclass_tran......
  • 当读取字节时,Python 将 \n 解释为 0xd0
    换行符被解释为Ð(0xd0)而不是(0x0a),我真的不知道如何解决这个问题。我也不知道从哪里开始。当尝试使用此代码时,它将0x0a读为0xd0。withopen(path,"rb")asroot:b_arr=root.read()+b""print("Processing...")buffer=""b_arr......
  • 在Python 3中获取范围的特定形式
    当获取range(1,100)时,我得到:[1,2,3,4,5...99]我需要像这个范围的zip之类的东西:[50,49,51,48,52,47,53...99]如何获取它?背景:这都是关于比特币谜题66的。首先我做了对过去已知的私钥进行线性回归预测,直到第65题为止。我......