0

I have jpeg images stored in binary formats. In need to edit these binaries to delete all the byte pairs that come before 0xff 0xd8 (as this is the initial part of my jpegs). The reason is that when I try to view these files in an image program, they won't open as long as I don't get rid of all the part of bytearray coming before this 0xff 0xd8 bytes. Here's what I tried so far:

data= open ('C:/Users/Umberto/Desktop/_BR_Browse.001_2065642654_1.BINARY', 'rb+')
edit= str (data.read () )
data.close ()
edit.find ('/xff/xd8')

but I always receive '-1' as index, for whatever I put as argument using "find" method. What's wrong with the code? Once I know the position of /xff/xd8, I would simply delete what comes before it somehow.

2
  • 1
    Use '\' instead of '/' More information here: stackoverflow.com/questions/3217334/… Commented Mar 4, 2013 at 14:14
  • 1
    Look for edit.find('\xff\xd8') instead? Commented Mar 4, 2013 at 14:15

2 Answers 2

2

Your escapes are the wrong way around. Try edit.find('\xff\xd8')

Sign up to request clarification or add additional context in comments.

Comments

0

Problem with this line:

edit.find ('/xff/xd8')

Use '\' instead of '/'

edit.find ('\xff\xd8')

More information here: Python: Searching/reading binary data

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.