Skip to content

Add / fix support for text read mode #122

Description

@nick-hahner
In [17]: lz4.frame.open(input_file, mode='rt', newline='', encoding='utf-8')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-ca68d3c17eba> in <module>()
----> 1 lz4.frame.open(input_file, mode='rt', newline='', encoding='utf-8')

/usr/local/lib/python3.6/site-packages/lz4/frame/__init__.py in open(filename, mode, encoding, errors, newline, block_size, block_linked, compression_level, content_checksum, block_checksum, auto_flush, return_bytearray, source_size)
    842         block_checksum=block_checksum,
    843         auto_flush=auto_flush,
--> 844         return_bytearray=return_bytearray,
    845     )
    846

/usr/local/lib/python3.6/site-packages/lz4/frame/__init__.py in __init__(self, filename, mode, block_size, block_linked, compression_level, content_checksum, block_checksum, auto_flush, return_bytearray, source_size)
    513             self._pos = 0
    514         else:
--> 515             raise ValueError('Invalid mode: {!r}'.format(mode))
    516
    517         if sys.version_info > (3, 6):

ValueError: Invalid mode: 'rt'

Looking at the source, it looks like mode is passed from

mode=mode,
to
if mode in ('r', 'rb'):

open() is happy with a mode of 'rt' and it passes it along unchanged to the LZ4FrameFile class which does not like 'rt'. Perhaps the mode should be changed to 'rb' when passing to the init method, or perhaps the init method should be happy with 'rt'.

Either way it breaks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions