Last active
August 29, 2015 14:24
-
-
Save tdshipley/85508efbe53b3691ca72 to your computer and use it in GitHub Desktop.
Ruby isJPEG? method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param [Object] block A 512 byte block to check if it contains a jpeg header in first 4 bytes | |
def isJPEG?(block) | |
# Encodings are diff between reading an image file and strings so block[0] == 0xFF wont work | |
# http://stackoverflow.com/questions/16815308/ruby-comparing-hex-value-to-string | |
jpeg_header_part = ['FFD8FF'].pack('H*') | |
return block[0,3] == jpeg_header_part && (block[3] == 0xe0.chr || block[3] == 0x0e1.chr) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment