lib/psd/resource.rb in psd-0.3.5 vs lib/psd/resource.rb in psd-0.4.0

- old
+ new

@@ -1,27 +1,26 @@ class PSD # Definition for a single Resource record. # # Most of the resources are options/preferences set by the user # or automatically by Photoshop. - class Resource < BinData::Record - endian :big + class Resource + attr_reader :type, :id, :name, :size + attr_accessor :data - string :type, read_length: 4 - uint16 :id - uint8 :name_len - stringz :name, read_length: :name_length - uint32 :res_size + def initialize(file) + @file = file + @data = {} + @type = nil + end - skip length: :resource_size + def parse + @type = @file.read_string(4) # Always 8BIM + @id = @file.read_short - #--- - # Really weird padding business - def name_length - Util.pad2(name_len + 1) - 1 - end + name_length = Util.pad2(@file.read(1).bytes.to_a[0] + 1) - 1 + @name = @file.read_string(name_length) - def resource_size - Util.pad2(res_size) + @size = Util.pad2(@file.read_int) end end end \ No newline at end of file