Sha256: 383267294004c5c35d835800d0ff647b80e3e4360439f660b331754c061022f2

Contents?: true

Size: 1.04 KB

Versions: 62

Compression:

Stored size: 1.04 KB

Contents

module CF
  typedef :pointer, :cfdataref

  attach_function 'CFDataCreate', [:pointer, :buffer_in, :cfindex], :cfdataref  
  attach_function 'CFDataGetLength', [:cfdataref], :cfindex  
  attach_function 'CFDataGetBytePtr', [:cfdataref], :pointer

  # Wrapper for CFData
  #
  #
  class Data < Base
    register_type("CFData")

    # Creates a CFData from a ruby string
    # @param [String] s the string to use
    # @return [CF::Data]
    def self.from_string(s)
      new(CF.CFDataCreate(nil, s, s.bytesize)).release_on_gc
    end

    # Creates a ruby string from the wrapped data. The encoding will always be ASCII_8BIT
    #
    # @return [String]
    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

    # The size in bytes of the CFData
    # @return [Integer]
    def size
      CF.CFDataGetLength(self)
    end

    alias_method :to_ruby, :to_s
  end
end

Version data entries

62 entries across 19 versions & 3 rubygems

Version Path
og-corefoundation-0.2.3 lib/corefoundation/data.rb
og-corefoundation-0.2.2 lib/corefoundation/data.rb
og-corefoundation-0.2.1 lib/corefoundation/data.rb
yakg-0.1.11 vendor/gems/ruby/2.0.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.11 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.11 vendor/gems/ruby/2.2.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.11 vendor/gems/ruby/1.8/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.11 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.10 vendor/gems/ruby/2.2.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.10 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.10 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.10 vendor/gems/ruby/1.8/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.10 vendor/gems/ruby/2.0.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.9 vendor/gems/ruby/2.0.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.9 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.9 vendor/gems/ruby/1.8/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.9 vendor/gems/ruby/2.2.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.9 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.8 vendor/gems/ruby/2.1.0/gems/corefoundation-0.2.0/lib/corefoundation/data.rb
yakg-0.1.8 vendor/gems/ruby/1.9.1/gems/corefoundation-0.2.0/lib/corefoundation/data.rb