Class: RDF::Raptor::FFI::V2::IOStream

Inherits:
FFI::ManagedStruct
  • Object
show all
Includes:
RDF::Raptor::FFI
Defined in:
lib/rdf/raptor/ffi/v2/iostream.rb

Overview

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

Constant Summary

Constants included from RDF::Raptor::FFI

ENGINE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RDF::Raptor::FFI

#version

Constructor Details

#initialize(ptr) ⇒ IOStream #initialize(handler) ⇒ IOStream #initialize(file) ⇒ IOStream

Returns a new instance of IOStream.

Overloads:

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Class Method Details

.release(ptr)

This method returns an undefined value.

Releases libraptor memory associated with this structure.

Parameters:

  • ptr (FFI::Pointer)


50
51
52
53
54
# File 'lib/rdf/raptor/ffi/v2/iostream.rb', line 50

def self.release(ptr)
  if @free_iostream
    V2.raptor_free_iostream(ptr)
  end
end