I am using WindLDR to produce PLC Ladder Diagrams. Files are saved as file_name.pjw
I wrote a little python script to decompress the pjw files, but now I want to recompress them. The file output differs however, and I’m not sure how to fix this.
This is how the original compressed file format shows up From the linux file utility:
$ file project01OG.pjw
project01OG.pjw: gzip compressed data, from TOPS/20, original size modulo 2^32 314621
The compression script produces this:
$ file project01.pjw
project01.pjw: gzip compressed data, was "project01.pjw", max compression, original size modulo 2^32 314621
Which is similar, but missing the bits about TOPS/20.
The decompression script:
#!/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)
The Compression script:
#!/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)
So I’m not sure how to implement the TOPS/20 bit of the compression. I am also curious about how to omit the filename from what the file utility list.
I tried filename=''
in the write loop. It kept throwing an error, so I took that out.
I tried asking ChatGPT, but it says something like edit the resulting file output in a hex editor, so… I’m not doing that.
I can link to a pjw file, or the decompressed file output if that would assist.