Class: AppInfo::PngUncrush::PngReader
- Defined in:
- lib/app_info/png_uncrush.rb
Overview
:nodoc:
Constant Summary collapse
- PNG_HEADER =
"\x89PNG\r\n\x1a\n".bytes
- CHUNK =
1024
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](offset, length) ⇒ Object
- #header ⇒ Object
-
#initialize(raw) ⇒ PngReader
constructor
A new instance of PngReader.
- #png? ⇒ Boolean
- #size ⇒ Object
- #unpack(format) ⇒ Object
Constructor Details
#initialize(raw) ⇒ PngReader
Returns a new instance of PngReader.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/app_info/png_uncrush.rb', line 21 def initialize(raw) @io = if raw.is_a?(String) StringIO.new(raw) elsif raw.respond_to?(:read) && raw.respond_to?(:eof?) raw else raise ArgumentError, "expected data as String or an object responding to read, got #{raw.class}" end @data = String.new end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/app_info/png_uncrush.rb', line 19 def data @data end |
Instance Method Details
#[](offset, length) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/app_info/png_uncrush.rb', line 50 def [](offset, length) while !@io.eof? && @data.length < offset + length data = @io.read(CHUNK) break unless data data.force_encoding(@data.encoding) if data.respond_to?(:encoding) @data << data end @data[offset, length] end |
#header ⇒ Object
42 43 44 |
# File 'lib/app_info/png_uncrush.rb', line 42 def header @header ||= self[0, 8] end |
#png? ⇒ Boolean
46 47 48 |
# File 'lib/app_info/png_uncrush.rb', line 46 def png? PNG_HEADER == header.bytes end |
#size ⇒ Object
34 35 36 |
# File 'lib/app_info/png_uncrush.rb', line 34 def size @io.size end |
#unpack(format) ⇒ Object
38 39 40 |
# File 'lib/app_info/png_uncrush.rb', line 38 def unpack(format) @io.unpack(format) end |