Commit 3781f711fb6e71fdfff67714d026a4cc7ca72086
1 parent
d397edb5
ooxml: implement skipping data in ZipSubFile
Showing
1 changed file
with
15 additions
and
3 deletions
oletools/ooxml.py
| ... | ... | @@ -198,12 +198,24 @@ class ZipSubFile(object): |
| 198 | 198 | |
| 199 | 199 | only re-positioning to start of file is allowed |
| 200 | 200 | """ |
| 201 | + CHUNK_SIZE = 4096 | |
| 201 | 202 | if pos == 0 and offset == io.SEEK_SET: |
| 202 | 203 | self.reset() |
| 203 | - elif pos == -self.pos and offset == io.SEEK_CUR: | |
| 204 | - self.reset() | |
| 204 | + elif offset == io.SEEK_CUR: | |
| 205 | + if pos == -self.pos: | |
| 206 | + self.reset() | |
| 207 | + elif pos == 0: | |
| 208 | + return | |
| 209 | + elif pos > 0: | |
| 210 | + skipped = 0 | |
| 211 | + n_chunks, leftover = divmod(pos, CHUNK_SIZE) | |
| 212 | + for _ in range(n_chunks): | |
| 213 | + self.read(CHUNK_SIZE) # just read and discard | |
| 214 | + self.read(leftover) | |
| 215 | + else: | |
| 216 | + raise NotImplementedError('could reset() and read()?') | |
| 205 | 217 | else: |
| 206 | - raise NotImplementedError('could reset() and read()') | |
| 218 | + raise NotImplementedError('could reset() and read()?') | |
| 207 | 219 | |
| 208 | 220 | def tell(self): |
| 209 | 221 | """ inform about position of next read """ | ... | ... |