I'm tinkering with a module which scans video files. The MP4 parser has a `discard_data` parameter which tells certain parts of the parser to discard some of the scanned data, particularly the MDAT box parse because I don't normally want to blow the machine's RAM on a huge video stream - I'm normally parsing out the semantic info such as metadata.

However, I would _like_ to keep it available in a frugal fashion if I can, and it seems to me that the mmap module is ideal: map the file into memory, use the file itself as the backing store, and return views of the mmap.

But slicing a mmap object returns a bytes, which I _imagine_ to be a copy of the file data instead of a view into the mapping (because bytes are supposed to be immutable, and in theory some other actor might change the file even though I myself have it mapped read only).

It seems obvious to me that a method returning a memoryview of the mapped file would be very handy here: no data copies at all, and not even any I/O unless the data are accessed. But I see no such method in the documentation.

Does anyone have any insight here?

Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to