From 17ae3fc3c7b4cc29fc54be9891d76147bebaa8bb Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 24 Nov 2017 17:54:55 +0100 Subject: [PATCH] ooxml: Add rough structure and idea for resetable zip stream --- oletools/ooxml.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+), 0 deletions(-) diff --git a/oletools/ooxml.py b/oletools/ooxml.py index 4984f7e..6711935 100644 --- a/oletools/ooxml.py +++ b/oletools/ooxml.py @@ -124,6 +124,27 @@ def is_ooxml(filename): return False +class ZipFileResetable(io.BufferedIOBase): + """ A file-like object like zip.open returns them, only can seek() to 0 + + ZipFile.open() gives file handles that can be read but not seek()ed since + the file is being decompressed in the background. This class implements a + reset() function which corresponds to a seek to 0 (which just closes the + stream and re-opens it behind the scenes + """ + + def __init__(self, container, filename, mode=None): + self.container = container + self.name = filename + self.handle = container.open(filename, mode) + + def read(self, size=None): + pass + + def seek(self, pos, offset): + pass + + class XmlParser(object): """ parser for OOXML files """ -- libgit2 0.21.4