Class: CFPropertyList::CFData

Inherits:
CFType
  • Object
show all
Defined in:
lib/rbCFTypes.rb

Overview

This class contains binary data values

Constant Summary collapse

DATA_BASE64 =

Base64 encoded data

0
DATA_RAW =

Raw data

1

Instance Attribute Summary

Attributes inherited from CFType

#value

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, format = DATA_BASE64) ⇒ CFData

set value to defined state, either base64 encoded or raw



163
164
165
166
167
168
169
170
# File 'lib/rbCFTypes.rb', line 163

def initialize(value=nil,format=DATA_BASE64)
  if(format == DATA_RAW)
    @raw_value = value
    @raw_value.blob = true
  else
    @value = value
  end
end

Instance Method Details

#decoded_valueObject

get base64 decoded value



178
179
180
181
182
# File 'lib/rbCFTypes.rb', line 178

def decoded_value
  @raw_value ||= String.new(Base64.decode64(@value))
  @raw_value.blob = true
  @raw_value
end

#encoded_valueObject

get base64 encoded value



173
174
175
# File 'lib/rbCFTypes.rb', line 173

def encoded_value
  @value ||= "\n#{Base64.encode64(@raw_value).gsub("\n", '').scan(/.{1,76}/).join("\n")}\n"
end

#to_binary(bplist) ⇒ Object

convert to binary



192
193
194
# File 'lib/rbCFTypes.rb', line 192

def to_binary(bplist)
  bplist.data_to_binary(decoded_value())
end

#to_xml(parser) ⇒ Object

convert to XML



185
186
187
188
189
# File 'lib/rbCFTypes.rb', line 185

def to_xml(parser)
  n = parser.new_node('data')
  n = parser.append_node(n, parser.new_text(encoded_value()))
  n
end