rudy.schockaert at pandora.be
Wed Jan 15 20:06:39 CET 2003
I didn't realize that string functions can also be used on pure binary data.
By the way, the files I want to scan are limited to 1 meg, so I don't see a
problem in putting the file entirely in memory.
schreef in bericht news:m3vg0qefdo.fsf at mira.informatik.hu-berlin.de...
> "Rudy Schockaert" <rudy.schockaert at pandora.be> writes:
> > I'm looking for a function that allows me to do a binary search in a
> > By binary search I mean searching for a sequence of bytes
> If you can accommodate to put the entire file into memory, I recommend
> the lines
> data = open("filename","rb").read()
> position = data.find(binary_substring)
> Here, binary_substring is the string object that you search for.
> If you cannot read the entire file into memory, I recommend to read
> sized chunks (of atleast twice the substring size). I'm not aware of a
> cookbook-style implementation of such a search algorithm, so when you
> are done, please submit it to the cookbook. Make sure you properly
> deal with the case where the substring crosses a block boundary.
More information about the Python-list