class RDF::Raptor::FFI::V1::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  [V1::IOStreamHandler] handler

@overload initialize(file)

@param  [File, Tempfile] file
Calls superclass method
# File lib/rdf/raptor/ffi/v1/iostream.rb, line 21
def initialize(ptr_or_obj, **options)
  ptr = case ptr_or_obj
    when FFI::Pointer
      ptr_or_obj
    when V1::IOStreamHandler
      @handler = ptr_or_obj # prevents premature GC
      V1.raptor_new_iostream_from_handler2(self, @handler)
    when File, Tempfile
      V1.raptor_new_iostream_to_filename(File.expand_path(ptr_or_obj.path))
    when false
      V1.raptor_new_iostream_to_sink()
    else nil
  end
  
  @free_iostream = options[:free_iostream] || true
  
  raise ArgumentError, "invalid argument: #{ptr_or_obj.inspect}" if ptr.nil? || ptr.null?
  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/v1/iostream.rb, line 46
def self.release(ptr)
  if @free_iostrem
    V1.raptor_free_iostream(ptr)
  end
end