netvl / immeta

Image metadata inspection library in Rust
MIT License
24 stars 18 forks source link

Reimplement JPEG and GIF parsers to discard BufReader usage #3

Closed netvl closed 8 years ago

netvl commented 8 years ago

BufReader is used internally in JPEG and GIF metadata parsers which may lead to surprising results. Ideally immeta should read as little as possible from the stream; if BufRead is used inside, it may read a lot more than necessary.

netvl commented 8 years ago

JPEG can't be reimplemented sensibly without BufReader, and while GIF can be, I've eventually decided to always require BufRead instead of just Read. I don't think this would make any significant inconveniences (any reader could be wrapped into a BufReader), however, this would be a performance win in many cases (lots of formats require skipping through large amounts of data, which is more performant with a buffered reader).

I've also added another method to LoadableMetadata trait, read_from_seek(), which accepts R: BufRead + Seek and by default delegates to read<R: BufRead>(); however, implementations may override it to provide more efficient parsing using seeking. This is already present in the master branch.