我正在使用 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:
-
gzip Compatibility:
The
gzip
library in Python inherently follows the gzip standard. You're not modifying the compression algorithm itself. - Identical Decompressed Data: If you decompress both the original and your re-compressed files, you'll find the content is identical.
-
"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:
- 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.
-
Testing with WindLDR:
The most important test is whether WindLDR can successfully open and use your recompressed
.pjw
files.