Commit 989ead6cf6d848794a51bc63a4acd8e5ea4373fa
1 parent
cbbbfa23
xls_parser: close stream after xlsb-parsing; update stream constructor
Showing
1 changed file
with
15 additions
and
5 deletions
oletools/xls_parser.py
| ... | ... | @@ -55,7 +55,8 @@ import sys |
| 55 | 55 | import os.path |
| 56 | 56 | from struct import unpack |
| 57 | 57 | import logging |
| 58 | -from record_base import OleRecordFile, OleRecordStream, OleRecordBase, test | |
| 58 | +from record_base import OleRecordFile, OleRecordStream, OleRecordBase, test, \ | |
| 59 | + STGTY_STREAM | |
| 59 | 60 | |
| 60 | 61 | |
| 61 | 62 | # === PYTHON 2+3 SUPPORT ====================================================== |
| ... | ... | @@ -452,10 +453,19 @@ class XlsbBeginSupBook(XlsbRecord): |
| 452 | 453 | ############################################################################### |
| 453 | 454 | |
| 454 | 455 | |
| 455 | -def parse_xlsb_part(stream, _, filename): | |
| 456 | - """ Excel xlsb files also have a record structure. iter records """ | |
| 457 | - for record in XlsbStream(stream, filename).iter_records(): | |
| 458 | - yield record | |
| 456 | +def parse_xlsb_part(file_stream, _, filename): | |
| 457 | + """ Excel xlsb files also have bin files with record structure. iter! """ | |
| 458 | + xlsb_stream = None | |
| 459 | + try: | |
| 460 | + xlsb_stream = XlsbStream(file_stream, file_stream.size, filename, | |
| 461 | + STGTY_STREAM) | |
| 462 | + for record in xlsb_stream.iter_records(): | |
| 463 | + yield record | |
| 464 | + except Exception: | |
| 465 | + raise | |
| 466 | + finally: | |
| 467 | + if xlsb_stream is not None: | |
| 468 | + xlsb_stream.close() | |
| 459 | 469 | |
| 460 | 470 | |
| 461 | 471 | ############################################################################### | ... | ... |