Python Forum

Full Version: Using mmap.mmap and re.finditer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
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
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