class RDF::Raptor::FFI::V2::IOStream

This class provides an I/O stream that can write to filenames, ‘FILE*`, strings and user-defined output via callbacks.

@see librdf.org/raptor/api-1.4/raptor-section-iostream.html

Public Class Methods

new(ptr_or_obj, **options) click to toggle source

@overload initialize(ptr)

@param  [FFI::Pointer] ptr

@overload initialize(handler)

@param  [V2::IOStreamHandler] handler

@overload initialize(file)

@param  [File, Tempfile] file
Calls superclass method
# File lib/rdf/raptor/ffi/v2/iostream.rb, line 26
def initialize(ptr_or_obj, **options)
  ptr = case ptr_or_obj
    when FFI::Pointer
      ptr_or_obj
    when V2::IOStreamHandler
      @handler = ptr_or_obj # prevents premature GC
      V2.raptor_new_iostream_from_handler(V2.world, self, @handler)
    when File, Tempfile
      V2.raptor_new_iostream_to_filename(V2.world, File.expand_path(ptr_or_obj.path))
    when false
      V2.raptor_new_iostream_to_sink(V2.world)
    else nil
  end
  raise ArgumentError, "invalid argument: #{ptr_or_obj.inspect}" if ptr.nil? || ptr.null?
  
  @free_iostream = options[:free_iostream] || true
  super(ptr)
end
release(ptr) click to toggle source

Releases ‘libraptor` memory associated with this structure.

@param [FFI::Pointer] ptr @return [void]

# File lib/rdf/raptor/ffi/v2/iostream.rb, line 50
def self.release(ptr)
  if @free_iostream
    V2.raptor_free_iostream(ptr)
  end
end