Class: CF::Data

Inherits:
Base
  • Object
show all
Defined in:
lib/corefoundation/data.rb

Overview

Wrapper for CFData

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

check_cftype, #eql?, #equals?, #hash, #initialize, #inspect, #null?, #ptr=, #release, #release_on_gc, #retain, #to_cf, #to_ptr, typecast

Constructor Details

This class inherits a constructor from CF::Base

Class Method Details

.from_string(s) ⇒ CF::Data

Creates a CFData from a ruby string

Parameters:

  • s (String)

    the string to use

Returns:



17
18
19
# File 'lib/corefoundation/data.rb', line 17

def self.from_string(s)
  new(CF.CFDataCreate(nil, s, s.bytesize)).release_on_gc
end

Instance Method Details

#sizeInteger

The size in bytes of the CFData

Returns:



35
36
37
# File 'lib/corefoundation/data.rb', line 35

def size
  CF.CFDataGetLength(self)
end

#to_sString Also known as: to_ruby

Creates a ruby string from the wrapped data. The encoding will always be ASCII_8BIT

Returns:



24
25
26
27
28
29
30
31
# File 'lib/corefoundation/data.rb', line 24

def to_s
  ptr = CF.CFDataGetBytePtr(self)
  if CF::String::HAS_ENCODING
    ptr.read_string(CF.CFDataGetLength(self)).force_encoding(Encoding::ASCII_8BIT)
  else
    ptr.read_string(CF.CFDataGetLength(self))
  end
end