Martin Vignali added the comment:

I'm okay with just testing the first two bytes, it's the method we currently 
use for our
internal tools.

But maybe it can be interesting, to add another test, in order to detect 
incomplete file
(created when a camera make a recording error for example, and very useful to 
detect, because an incomplete jpeg file, make a crash for a lot of application)

We use this patch of imghdr :

--------------------------------------
def test_jpeg(h, f):
    """JPEG data in JFIF or Exif format"""
    if not h.startswith(b'\xff\xd8'):#Test empty files, and incorrect start of 
file
        return None
    else:
        if f:#if we test a file, test end of jpeg
            f.seek(-2,2)
            if f.read(2).endswith(b'\xff\xd9'):
                return 'jpeg'
        else:#if we just test the header, consider this is a valid jpeg and not 
test end of file
            return 'jpeg'
-------------------------------------

----------
nosy: +mvignali

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16512>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to