[Python-ideas] struct.unpack should support open files

eryk sun eryksun at gmail.com
Tue Dec 25 17:51:18 EST 2018


On 12/24/18, Drew Warwick <dwarwick96 at gmail.com> wrote:
> The struct unpack API is inconvenient to use with files. I must do:
>
> struct.unpack(fmt, file.read(struct.calcsize(fmt))

Alternatively, we can memory-map the file via mmap. An important
difference is that the mmap buffer interface is low-level (e.g. no
file pointer and the offset has to be page aligned), so we have to
slice out bytes for the given offset and size. We can avoid copying
via memoryview slices. We can also use ctypes instead of
memoryview/struct.


More information about the Python-ideas mailing list