YeP
YeP

Reputation: 211

How to unzip a compound file in Python

I try to unzip a file type *.pcbdoc, it is the file format for Altium. I can see and extract the file structure using "open archive" in 7zip, however I can't seem to open it in Python. I have tried zipfile, py7zr, pyunpack and etc with no luck.

I understand that we don't know for sure what kind of zip format *.pcbdoc is, but how can 7zip open the archive? Can I do the same in python? Can someone give me some help? Thanks a lot.

What I have tried:

  1. import zipfile

zipfile.ZipFile(source_path).extractall(output_path)

got error: zipfile.BadZipFile: File is not a zip file

  1. import py7zr

py7zr.SevenZipFile(source_path, mode='r').extractall(output_path)

got error: py7zr.exceptions.Bad7zFile: not a 7z file

  1. from pyunpack import Archive

Archive(source_path).extractall(output_path)

got error: pyunpack.PatoolError: patool can not unpack, unknown archive format for file

Upvotes: 1

Views: 834

Answers (1)

YeP
YeP

Reputation: 211

Thanks for the help. Learning from the link in comment: link, I process .pcbdoc as olefile and it is pretty successful. Here is what I did:

import olefile    
f=olefile.OleFileIO(source_path).openstream(subfolder_path)    
print(f.read().decode(errors="ignore"))

Upvotes: 2

Related Questions