class FileData::Jpeg
Represents a Jpeg
image stream
Constants
- EOI_BYTES
- INVALID_HEADER_MSG
- SECTION_HEADER_SIZE
- SOI_BYTES
Public Class Methods
current_section(stream, marker)
click to toggle source
def self.section_pos?(stream)
# Make sure that there are enough bytes for a section header. # This also handles an ending two byte JPEG EOI sequence. stream.size >= SECTION_HEADER_SIZE
end
# File lib/file_data/file_types/jpeg.rb, line 41 def self.current_section(stream, marker) content_stream = Helpers::SizedField.create_view(stream, 2) JpegSection.new(marker, content_stream) end
each_section(stream)
click to toggle source
# File lib/file_data/file_types/jpeg.rb, line 13 def self.each_section(stream) view = Helpers::StreamView.new(stream) read_header(view) Enumerator.new { |e| yield_sections(view, e) }.lazy end
read_header(stream)
click to toggle source
# File lib/file_data/file_types/jpeg.rb, line 19 def self.read_header(stream) soi = stream.each_byte.take(SOI_BYTES.size) raise INVALID_HEADER_MSG unless soi == SOI_BYTES end
yield_sections(stream, enumerator)
click to toggle source
# File lib/file_data/file_types/jpeg.rb, line 24 def self.yield_sections(stream, enumerator) until stream.eof? marker = stream.each_byte.take(2) break if marker == EOI_BYTES section = current_section(stream, marker) enumerator.yield section stream.seek(section.content_stream.end_pos + 1) end end