bojand / infer

Small crate to infer file and MIME type by checking the magic number signature
MIT License
299 stars 28 forks source link

How many header bytes are needed form image id? #59

Closed gvasquez95 closed 2 years ago

gvasquez95 commented 2 years ago

Tried to figure it out by myself, but seems to be that docs could be misleading so I preferred to ask, given that:

  1. The original Go repo says only the initial 262 bytes of a max header size are needed
  2. The examples show a buffer with just 4 bytes and works for images
  3. In our tests 8 bytes are good enough, obviously if 4 bytes work.

The real question is for png and jpg how many bytes are actually required to be "sliced"?

gvasquez95 commented 2 years ago

reading on https://github.com/h2non/filetype/blob/master/matchers/image.go

seems like 4 bytes would be enough for png and jpg images.