-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closing a ZstdCompressionWriter or ZstdDecompressionWriter should not close underlying file #76
Comments
The behavior of stream wrappers and I'm pretty sure I found at least one example ( I understand your pain here. I'd prefer to change things once. And that change should match the behavior of other stream wrappers in Python. So I'll need to do some homework. Specifically:
|
I should mention that a workaround would be to use |
https://github.com/python/cpython/blob/master/Lib/gzip.py
fileobj is the output object fileobj is not closed |
I've filed https://bugs.python.org/issue36129 to seek clarification from upstream. |
I'm having a similar issue with zstd.ZstdDecompressor().stream_reader not closing the inner file when an outer TextIOWrapper closes. Can this also be addressed? |
Thanks for the report, @ghannum. While I think I know what you are saying, would you mind providing a use case showing the behavior and commenting exactly where you think things are misbehaving? I'm wondering if we're getting into trouble because we don't involve |
|
@indygreg any update on this? |
The reply to https://bugs.python.org/issue36129 says that |
Thanks for the response. It is an interesting question I hadn't thought of. Looking at the Python standard libraries, it seems this sort of control is assumed through the parameter type - ie. If you pass gzip.open a steam, it will not cascade a 'close' event (just borrowing the steam). But if you pass it a filename, it will handle all of the file-associated actions, even cascading the close through a hidden TextIOWrapper if requested (creating and owning the file handle and text wrapper). If the goal is to maintain the Python conventions, then perhaps a similar zstd.open function would be appropriate? |
I do plan to provide an |
Awesome. I'm looking forward to it! |
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: upon closing the file writer is also closing the underlying file, indygreg/python-zstandard#76
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
Is this the same bug? The nested zip file is corrupt when extracted. (oh, it may be that ZipFile simply doesn't close the underlying file when it is a stream and not a filename)
|
… stream The existing behavior of automatically calling close() on the underlying stream is not desired in all cases. See #76 for discussion. This commit adds an argument to ZstdCompressionWriter to control whether the inner stream is closed when the outer stream is closed. This will give consumers control over how to behave. We plan to implement this feature for all file-like types. After we're done, we'll revisit the default behavior.
…se the inner stream This is related to #76. So previous commit for more context.
…am is closed See #76 and previous commits for more context.
This completes our implementation of closefd support on all our IO classes to enable the consumer to have complete control over whether the inner stream should be closed on our close. See prior commits and #76 for more context.
I just pushed some commits to add |
This completes our implementation of closefd support on all our IO classes to enable the consumer to have complete control over whether the inner stream should be closed on our close. See prior commits and #76 for more context.
… stream The existing behavior of automatically calling close() on the underlying stream is not desired in all cases. See #76 for discussion. This commit adds an argument to ZstdCompressionWriter to control whether the inner stream is closed when the outer stream is closed. This will give consumers control over how to behave. We plan to implement this feature for all file-like types. After we're done, we'll revisit the default behavior.
…se the inner stream This is related to #76. So previous commit for more context.
…am is closed See #76 and previous commits for more context.
This completes our implementation of closefd support on all our IO classes to enable the consumer to have complete control over whether the inner stream should be closed on our close. See prior commits and #76 for more context.
I'm about to close this issue via a pushed commit. The state of the API will be as follows:
While the issue summary requests that |
This makes it consistent with stream_writer and inline with what Python developers recommend. See discussion in #76.
According to conversation in #76 and linked from there, flush() should propagate. This commit makes that change for ZstdCompressionWriter.flush().
This makes behavior consistent with ZstdCompressionWriter. See #76 for discussion on this topic.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
File interface is currently broken in python-zstandard: indygreg/python-zstandard#76 As a workaround using internal file wrapper.
The changes to support ZstdCompressionWriter and ZstdDecompressionWriter without a context mananger has broken use cases where they are being used in a context manager.
Upon a close, the writers should not close their underlying file objects. It should be up to the caller to close the file objects.
We are passing in StringIO objects to the writers and they get closed upon exit--throwing out the buffer. This technique works with other compression libraries.
The text was updated successfully, but these errors were encountered: