Skip to content

Commit

Permalink
Try to implement PipedGzipWriter.flush()
Browse files Browse the repository at this point in the history
This doesn’t work.

See #8
  • Loading branch information
marcelm committed May 8, 2018
1 parent 7e7ad82 commit d7b56e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_xopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,13 @@ def test_bare_read_from_gz():
def test_read_piped_gzip():
with PipedGzipReader('tests/hello.gz', 'rt') as f:
assert f.read() == 'hello'


def test_flush():
with temporary_path('out.gz') as path:
f = xopen(path, 'wt')
f.write('hello')
f.flush()
# File is not closed here intentionally
f2 = xopen(path, 'rt')
assert f2.read() == 'hello'
6 changes: 6 additions & 0 deletions xopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def __init__(self, path, mode='wt'):
def write(self, arg):
self._file.write(arg)

def flush(self):
for i in range(3): # because I don’t know in which order to do this
self.process.stdin.flush()
self.outfile.flush()
self._file.flush()

def close(self):
self.closed = True
self._file.close()
Expand Down

0 comments on commit d7b56e3

Please sign in to comment.