Class: RDF::Raptor::FFI::V1::IOStream

Inherits:
FFI::ManagedStruct
  • Object
show all
Includes:
RDF::Raptor::FFI
Defined in:
lib/rdf/raptor/ffi/v1/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)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Class Method Details

.release(ptr)

This method returns an undefined value.

Releases libraptor memory associated with this structure.

Parameters:

  • ptr (FFI::Pointer)


46
47
48
49
50
# File 'lib/rdf/raptor/ffi/v1/iostream.rb', line 46

def self.release(ptr)
  if @free_iostrem
    V1.raptor_free_iostream(ptr)
  end
end