From d7b56e3afd2e2c2f16066b77ad6bf4eaf37c75df Mon Sep 17 00:00:00 2001 From: Marcel Martin Date: Tue, 8 May 2018 10:44:07 +0200 Subject: [PATCH] Try to implement PipedGzipWriter.flush() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn’t work. See #8 --- tests/test_xopen.py | 10 ++++++++++ xopen.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/tests/test_xopen.py b/tests/test_xopen.py index ba04eee..7efefff 100644 --- a/tests/test_xopen.py +++ b/tests/test_xopen.py @@ -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' diff --git a/xopen.py b/xopen.py index 9c09214..3238bb0 100644 --- a/xopen.py +++ b/xopen.py @@ -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()