Python Forum
Using mmap.mmap and re.finditer
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using mmap.mmap and re.finditer
#1
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
Reply
#2
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
Reply
#3
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random access binary files with mmap - drastically slows with big files danart 1 3,908 Jun-17-2019, 10:45 AM
Last Post: danart
  re.finditer issue, output is blank anna 1 2,335 Feb-07-2019, 10:41 AM
Last Post: stranac
  Dealing with strings thru mmap in Python doublezero 4 7,936 Mar-01-2017, 06:33 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020