Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Relax "bytes" requirement when reading #572

Open
smurfix opened this issue Oct 7, 2023 · 1 comment
Open

Relax "bytes" requirement when reading #572

smurfix opened this issue Oct 7, 2023 · 1 comment

Comments

@smurfix
Copy link

smurfix commented Oct 7, 2023

The unpacker currently requires the file to return bytes.

cdef read_from_file(self):
        next_bytes = self.file_like_read(
                min(self.read_size,
                    self.max_buffer_size - (self.buf_tail - self.buf_head)
                    ))
        if next_bytes:
            self.append_buffer(PyBytes_AsString(next_bytes), PyBytes_Size(next_bytes))
        else:
            self.file_like = None

Is it possible to relax this?

The returned object must of course support the buffer protocol, but beyond that it shouldn't be required to be a bytes type. It could be a memoryview into an in-memory "file". There should be no requirement to copy the data; the unpacker does that anyway.

@methane
Copy link
Member

methane commented May 6, 2024

I never see such file-like. By typing.IOBase, read() must return str or bytes.
Is that file-like existing widely-used library? Or is it just in your program?

You can use Unpacker.feed(). Isn't it simpler than custom made file-like returning memoryview?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants