Class: CFPropertyList::CFData

Inherits:
CFType
  • Object
show all
Defined in:
lib/cfpropertylist/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



235
236
237
238
239
240
241
# File 'lib/cfpropertylist/rbCFTypes.rb', line 235

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

Instance Method Details

#decoded_valueObject

get base64 decoded value



249
250
251
# File 'lib/cfpropertylist/rbCFTypes.rb', line 249

def decoded_value
  @raw_value ||= Blob.new(Base64.decode64(@value))
end

#encoded_valueObject

get base64 encoded value



244
245
246
# File 'lib/cfpropertylist/rbCFTypes.rb', line 244

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



261
262
263
# File 'lib/cfpropertylist/rbCFTypes.rb', line 261

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

#to_plain(plist) ⇒ Object



265
266
267
# File 'lib/cfpropertylist/rbCFTypes.rb', line 265

def to_plain(plist)
  "<" + decoded_value.unpack("H*").join("") + ">"
end

#to_xml(parser) ⇒ Object

convert to XML



254
255
256
257
258
# File 'lib/cfpropertylist/rbCFTypes.rb', line 254

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