Python Forum
Using mmap.mmap and re.finditer - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Using mmap.mmap and re.finditer (/thread-3038.html)



Using mmap.mmap and re.finditer - Larz60+ - Apr-26-2017

Does anyone have an example of using Using mmap.mmap
and re.finditer with a marker to split binary files?

Forgot to add ... on binary data


RE: Using mmap.mmap and re.finditer - Larz60+ - Apr-26-2017

Found the following code on stackoverflow:
here

import mmap
import re

with open('somefile', 'rb') as fin:
  mf = mmap.mmap(fin.fileno(), 0, access=mmap.ACCESS_READ)
  markers = re.finditer('(.*?)MARKER', mf)
  for marker in markers:
    print (marker.group(1))
This looks like exactly what I'm looking for ... Now to test
I'll report back on how it works


RE: Using mmap.mmap and re.finditer - wavic - Apr-26-2017

The only thing I remember about mmap is that it allows me to make a storage in memory and use it like a real one. If I am not wrong. I'm not on the Earth right now. Don't feel well


RE: Using mmap.mmap and re.finditer - Larz60+ - Apr-26-2017

That is correct.
I know how that works,
what I was trying to do was place markers in the memory map with re.finditer
so that I could extract any of the 170,000 items that are in it.

I've since succeeded, so am OK