| |
- OleFileIO
class OleFileIO |
|
OLE container object
This class encapsulates the interface to an OLE 2 structured
storage file. Use the {@link listdir} and {@link openstream} methods to
access the contents of this file.
Object names are given as a list of strings, one for each subentry
level. The root entry should be omitted. For example, the following
code extracts all image streams from a Microsoft Image Composer file:
ole = OleFileIO("fan.mic")
for entry in ole.listdir():
if entry[1:2] == "Image":
fin = ole.openstream(entry)
fout = open(entry[0:1], "wb")
while True:
s = fin.read(8192)
if not s:
break
fout.write(s)
You can use the viewer application provided with the Python Imaging
Library to view the resulting files (which happens to be standard
TIFF files). |
|
Methods defined here:
- __init__(self, filename=None, raise_defects=40)
- Constructor for OleFileIO class.
filename: file to open.
raise_defects: minimal level for defects to be raised as exceptions.
(use DEFECT_FATAL for a typical application, DEFECT_INCORRECT for a
security-oriented application, see source code for details)
- close(self)
- close the OLE file, to release the file object
- dumpdirectory(self)
- Dump directory (for debugging only)
- dumpfat(self, fat, firstindex=0)
- Displays a part of FAT in human-readable form for debugging purpose
- dumpsect(self, sector, firstindex=0)
- Displays a sector in a human-readable form, for debugging purpose.
- exists(self, filename)
- Test if given filename exists as a stream or a storage in the OLE
container.
filename: path of stream in storage tree. (see openstream for syntax)
return: True if object exist, else False.
- get_metadata(self)
- Parse standard properties streams, return an OleMetadata object
containing all the available metadata.
(also stored in the metadata attribute of the OleFileIO object)
new in version 0.25
- get_rootentry_name(self)
- Return root entry name. Should usually be 'Root Entry' or 'R' in most
implementations.
- get_size(self, filename)
- Return size of a stream in the OLE container, in bytes.
filename: path of stream in storage tree (see openstream for syntax)
return: size in bytes (long integer)
raise: IOError if file not found, TypeError if this is not a stream.
- get_type(self, filename)
- Test if given filename exists as a stream or a storage in the OLE
container, and return its type.
filename: path of stream in storage tree. (see openstream for syntax)
return: False if object does not exist, its entry type (>0) otherwise:
- STGTY_STREAM: a stream
- STGTY_STORAGE: a storage
- STGTY_ROOT: the root entry
- getctime(self, filename)
- Return creation time of a stream/storage.
filename: path of stream/storage in storage tree. (see openstream for
syntax)
return: None if creation time is null, a python datetime object
otherwise (UTC timezone)
new in version 0.26
- getmtime(self, filename)
- Return modification time of a stream/storage.
filename: path of stream/storage in storage tree. (see openstream for
syntax)
return: None if modification time is null, a python datetime object
otherwise (UTC timezone)
new in version 0.26
- getproperties(self, filename, convert_time=False, no_conversion=None)
- Return properties described in substream.
filename: path of stream in storage tree (see openstream for syntax)
convert_time: bool, if True timestamps will be converted to Python datetime
no_conversion: None or list of int, timestamps not to be converted
(for example total editing time is not a real timestamp)
return: a dictionary of values indexed by id (integer)
- getsect(self, sect)
- Read given sector from file on disk.
sect: sector index
returns a string containing the sector data.
- listdir(self, streams=True, storages=False)
- Return a list of streams stored in this file
streams: bool, include streams if True (True by default) - new in v0.26
storages: bool, include storages if True (False by default) - new in v0.26
(note: the root storage is never included)
- loaddirectory(self, sect)
- Load the directory.
sect: sector index of directory stream.
- loadfat(self, header)
- Load the FAT table.
- loadfat_sect(self, sect)
- Adds the indexes of the given sector to the FAT
sect: string containing the first FAT sector, or array of long integers
return: index of last FAT sector.
- loadminifat(self)
- Load the MiniFAT table.
- open(self, filename)
- Open an OLE2 file.
Reads the header, FAT and directory.
filename: string-like or file-like object
- openstream(self, filename)
- Open a stream as a read-only file object (StringIO).
filename: path of stream in storage tree (except root entry), either:
- a string using Unix path syntax, for example:
'storage_1/storage_1.2/stream'
- a list of storage filenames, path to the desired stream/storage.
Example: ['storage_1', 'storage_1.2', 'stream']
return: file object (read-only)
raise IOError if filename not found, or if this is not a stream.
- sect2array(self, sect)
- convert a sector to an array of 32 bits unsigned integers,
swapping bytes on big endian CPUs such as PowerPC (old Macs)
| |