CFPropertyList 2.0.10 → 2.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,19 +90,19 @@ module CFPropertyList
90
90
  offsets = []
91
91
 
92
92
  0.upto(@object_table.size-1) do |i|
93
- binary_str += @object_table[i]
93
+ binary_str << @object_table[i]
94
94
  offsets[i] = object_offset
95
95
  object_offset += @object_table[i].bytesize
96
96
  end
97
97
 
98
98
  offsets.each do |offset|
99
- binary_str += Binary.pack_it_with_size(offset_size,offset)
99
+ binary_str << "#{Binary.pack_it_with_size(offset_size,offset)}"
100
100
  end
101
101
 
102
- binary_str += [offset_size, @object_ref_size].pack("x6CC")
103
- binary_str += [@count_objects].pack("x4N")
104
- binary_str += [0].pack("x4N")
105
- binary_str += [table_offset].pack("x4N")
102
+ binary_str << [offset_size, @object_ref_size].pack("x6CC")
103
+ binary_str << [@count_objects].pack("x4N")
104
+ binary_str << [0].pack("x4N")
105
+ binary_str << [table_offset].pack("x4N")
106
106
 
107
107
  return binary_str
108
108
  end
@@ -472,7 +472,7 @@ module CFPropertyList
472
472
  elsif(value.is_a?(CFData)) then
473
473
  val = value.decoded_value
474
474
  @int_size += Binary.bytes_size_int(val.length)
475
- @misc_size += val.length
475
+ @misc_size += val.length + 1
476
476
  @count_objects += 1
477
477
  return
478
478
  end
@@ -630,7 +630,7 @@ module CFPropertyList
630
630
  bdata = Binary.type_bytes("a", val.value.size) # a is 1010, type indicator for arrays
631
631
 
632
632
  val.value.each do |v|
633
- bdata += Binary.pack_it_with_size(@object_ref_size, v.to_binary(self));
633
+ bdata << Binary.pack_it_with_size(@object_ref_size, v.to_binary(self));
634
634
  end
635
635
 
636
636
  @object_table[saved_object_count] = bdata
@@ -647,11 +647,11 @@ module CFPropertyList
647
647
  val.value.each_key do |k|
648
648
  str = CFString.new(k)
649
649
  key = str.to_binary(self)
650
- bdata += Binary.pack_it_with_size(@object_ref_size,key)
650
+ bdata << Binary.pack_it_with_size(@object_ref_size,key)
651
651
  end
652
652
 
653
653
  val.value.each_value do |v|
654
- bdata += Binary.pack_it_with_size(@object_ref_size,v.to_binary(self))
654
+ bdata << Binary.pack_it_with_size(@object_ref_size,v.to_binary(self))
655
655
  end
656
656
 
657
657
  @object_table[saved_object_count] = bdata
@@ -3,6 +3,7 @@
3
3
  require 'libxml'
4
4
  require 'kconv'
5
5
  require 'date'
6
+ require 'time'
6
7
 
7
8
  #
8
9
  # CFPropertyList implementation
@@ -57,15 +58,20 @@ module CFPropertyList
57
58
  end
58
59
  end
59
60
 
60
- dirname = File.dirname(__FILE__)
61
- require dirname + '/rbCFPlistError.rb'
62
- require dirname + '/rbCFTypes.rb'
63
- require dirname + '/rbXMLCFPropertyList.rb'
64
- require dirname + '/rbBinaryCFPropertyList.rb'
61
+ class String
62
+ unless("".respond_to?(:blob) && "".respond_to?(:blob=)) then
63
+ # The blob status of this string (to set to true if a binary string)
64
+ attr_accessor :blob
65
+ end
65
66
 
66
- require 'iconv' unless "".respond_to?("encode")
67
+ unless("".respond_to?(:blob?)) then
68
+ # Returns whether or not +str+ is a blob.
69
+ # @return [true,false] If true, this string contains binary data. If false, its a regular string
70
+ def blob?
71
+ @blob
72
+ end
73
+ end
67
74
 
68
- class String
69
75
  unless("".respond_to?(:bytesize)) then
70
76
  def bytesize
71
77
  self.length
@@ -73,6 +79,13 @@ class String
73
79
  end
74
80
  end
75
81
 
82
+ dirname = File.dirname(__FILE__)
83
+ require dirname + '/rbCFPlistError.rb'
84
+ require dirname + '/rbCFTypes.rb'
85
+ require dirname + '/rbXMLCFPropertyList.rb'
86
+ require dirname + '/rbBinaryCFPropertyList.rb'
87
+
88
+ require 'iconv' unless "".respond_to?("encode")
76
89
 
77
90
  module CFPropertyList
78
91
  # Create CFType hierarchy by guessing the correct CFType, e.g.
@@ -95,11 +108,11 @@ module CFPropertyList
95
108
  elsif(object.is_a?(TrueClass) || object.is_a?(FalseClass)) then
96
109
  return CFBoolean.new(object)
97
110
  elsif(object.is_a?(String)) then
98
- return CFString.new(object)
111
+ return object.blob? ? CFData.new(object, CFData::DATA_RAW) : CFString.new(object)
112
+ elsif(object.is_a?(IO)) then
113
+ return CFData.new(object.read(), CFData::DATA_RAW)
99
114
  elsif(object.is_a?(Time) || object.is_a?(DateTime) || object.is_a?(Date)) then
100
115
  return CFDate.new(object)
101
- elsif(object.is_a?(IO)) then
102
- return CFData.new(object.read, CFData::DATA_RAW)
103
116
  elsif(object.is_a?(Array)) then
104
117
  ary = Array.new
105
118
  object.each do
@@ -157,20 +157,28 @@ module CFPropertyList
157
157
  # set value to defined state, either base64 encoded or raw
158
158
  def initialize(value=nil,format=DATA_BASE64)
159
159
  if(format == DATA_RAW) then
160
- @value = Base64.encode64(value)
160
+ @raw_value = value
161
+ @raw_value.blob = true
161
162
  else
162
163
  @value = value
163
164
  end
164
165
  end
165
166
 
167
+ # get base64 encoded value
168
+ def encoded_value
169
+ @value ||= Base64.encode64(@raw_value)
170
+ end
171
+
166
172
  # get base64 decoded value
167
173
  def decoded_value
168
- return Base64.decode64(@value)
174
+ @raw_value ||= String.new(Base64.decode64(@value))
175
+ @raw_value.blob = true
176
+ @raw_value
169
177
  end
170
178
 
171
179
  # convert to XML
172
180
  def to_xml
173
- return LibXML::XML::Node.new('data') << LibXML::XML::Node.new_text(@value)
181
+ return LibXML::XML::Node.new('data') << LibXML::XML::Node.new_text(encoded_value())
174
182
  end
175
183
 
176
184
  # convert to binary
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CFPropertyList
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 10
10
- version: 2.0.10
9
+ - 11
10
+ version: 2.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Kruse
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-14 00:00:00 +02:00
18
+ date: 2010-08-26 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency