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
compression_wrapper
compatibility issue
#332
Comments
compression_wrapper
compatibility issue
compression_wrapper
compatibility issuecompression_wrapper
compatibility issue
Upon investigation, it seems like: from smart_open.smart_open_lib import _compression_wrapper
smart_open.compression_wrapper = _compression_wrapper will restore this (desirable) functionality. @mpenkov I'd strongly prefer to avoid such monkey-patching shenanigans. Do you see a better way? If not, can we bring |
What is the use case here? What are you attempting to achieve, and what are the parameters you're passing to the wrapper? |
Parameter 1 = We're wrapping an open file-like binary object so that it decompresses transparently. |
I demoted compression_wrapper to be an internal function (it's called _compression_wrapper) when I redesigned the smart_open library over a year ago. My reasoning for making it internal was:
The main benefits of demoting such functions to internal is a cleaner API. Here's a better way to satisfy your use case than the import-rename pattern you suggested: >>> import io, gzip
>>>
>>> # prepare some gzipped data
>>> buf = io.BytesIO()
>>> with gzip.GzipFile(fileobj=buf, 'w') as fout: fout.write(b'this is a bytestring')
>>> buf.seek(0)
0
>>> # use case starts here
>>> buf.name = 'file.gz' # add a .name attribute so smart_open knows what compressor to use
>>> import smart_open
>>> smart_open.open(buf, 'rb').read() # will gzip-decompress transparently
b'this is a bytestring' If your file object already has an appropriate .name, then you don't have to add one. |
This used to work in 1.5.6, perhaps even later:
It doesn't work now,
smart_open.compression_wrapper
no longer exists.What's the reason? I cannot find anything in the CHANGELOG.
The text was updated successfully, but these errors were encountered: