Skip to content

Commit

Permalink
bufferedwriter close fix: (#36)
Browse files Browse the repository at this point in the history
* bufferedwriter close fix:
- add close_stream option (defaulting to true) to indicate if underlying stream should be closed to match pre-1.5.2 behavior
- archiveiterator does not close underlying stream, as before, only the decompressor. Fixes #35
- tests: add tests for close_stream true/false
- bump version to 1.5.3, update changelist

* bufferedreader: an even simpler fix, remove close_stream option, just add separate close_decompressor()
to close decompressor only, called from ArchiveIterator
BufferedReader.close() also closes decompressor

* update CHANGELIST.rst
  • Loading branch information
ikreymer authored Jun 1, 2018
1 parent 575d16f commit 95d5dcd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELIST.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.5.3
~~~~~

- ArchiveIterator calls new ``close_decompressor()`` function in BufferedReader instead of close() to only close decompressor, not underlying stream. `#35 <https://github.com/webrecorder/warcio/issues/35>`_


1.5.2
~~~~~

Expand All @@ -7,6 +13,7 @@
- ``ArchiveIterator.close()`` added which calls ``decompressor.flush()`` to address possible issues in `#34 <https://github.com/webrecorder/warcio/issues/34>`_
- Switch ``Warc-Record-ID`` uuid creation to ``uuid4()`` from ``uuid1()``


1.5.1
~~~~~

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools.command.test import test as TestCommand
import glob

__version__ = '1.5.2'
__version__ = '1.5.3'


class PyTest(TestCommand):
Expand Down
2 changes: 1 addition & 1 deletion warcio/archiveiterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __next__(self):
def close(self):
self.record = None
if self.reader:
self.reader.close()
self.reader.close_decompressor()
self.reader = None

def _iterate_records(self):
Expand Down
9 changes: 8 additions & 1 deletion warcio/bufferedreaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class BufferedReader(object):
def __init__(self, stream, block_size=BUFF_SIZE,
decomp_type=None,
starting_data=None):

self.stream = stream
self.block_size = block_size

Expand Down Expand Up @@ -222,9 +223,15 @@ def rem_length(self):
return rem

def close(self):
self.stream = None
if self.stream:
self.stream.close()
self.stream = None

self.buff = None

self.close_decompressor()

def close_decompressor(self):
if self.decompressor:
self.decompressor.flush()
self.decompressor = None
Expand Down

0 comments on commit 95d5dcd

Please sign in to comment.