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(a) ⇒ Object
Constructor Details
#initialize(raw) ⇒ PngReader
Returns a new instance of PngReader.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/app_info/png_uncrush.rb', line 20 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.
18 19 20 |
# File 'lib/app_info/png_uncrush.rb', line 18 def data @data end |
Instance Method Details
#[](offset, length) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/app_info/png_uncrush.rb', line 48 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
40 41 42 |
# File 'lib/app_info/png_uncrush.rb', line 40 def header @header ||= self[0, 8] end |
#png? ⇒ Boolean
44 45 46 |
# File 'lib/app_info/png_uncrush.rb', line 44 def png? PNG_HEADER == header.bytes end |
#size ⇒ Object
32 33 34 |
# File 'lib/app_info/png_uncrush.rb', line 32 def size @io.size end |
#unpack(a) ⇒ Object
36 37 38 |
# File 'lib/app_info/png_uncrush.rb', line 36 def unpack(a) @io.unpack(a) end |