in reply to Weird file extraction problem

If the file is a PNG image file (see Portable_Network_Graphics) then a better technique is probably to actually parse the file to find the chunk of interest then simply extract the chunk. The Wikipedia article gives all the information you need to understand the file format and a little playing around with read, unpack and seek should give you the main tools you need to write the code.

Premature optimization is the root of all job security