class RDF::Raptor::FFI::V2::IOStreamHandler

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

Constants

HANDLERS

Attributes

io[RW]

The IO object to operate upon.

@return [IO]

Public Class Methods

new(ptr_or_io = nil) click to toggle source

@overload initialize(ptr)

@param  [FFI::Pointer] ptr

@overload initialize(io)

@param  [IO, StringIO] io
Calls superclass method
# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 30
def initialize(ptr_or_io = nil)
  if ptr_or_io.respond_to?(:write)
    @io = ptr_or_io
    super()
  else
    case ptr_or_io
    when FFI::Pointer
      super(ptr_or_io)
    when nil
      super()
    else
      raise ArgumentError, "invalid argument: #{ptr_or_io.inspect}"
    end
  end
  initialize!
end

Public Instance Methods

define_handler(name, &block) click to toggle source

@param [Symbol, to_sym] name @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 146
def define_handler(name, &block)
  name = name.to_sym
  raise ArgumentError, "invalid IOStreamHandler function name: #{name}" unless HANDLERS.include?(name)
  @procs ||= {} # prevents premature GC of the procs
  @procs[name] = self[name] = block
end
finish=(func)
Alias for: finish_handler=
finish_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 98
def finish_handler=(func)
  define_handler(:finish, &func)
end
Also aliased as: finish=
init=(func)
Alias for: init_handler=
init_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 90
def init_handler=(func)
  define_handler(:init, &func)
end
Also aliased as: init=
initialize!() click to toggle source

@return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 49
def initialize!
  self[:version] = 2

  #define_handler(:init) do |context|
  #  $stderr.puts("#{self.class}: init")
  #end
  #define_handler(:finish) do |context|
  #  $stderr.puts("#{self.class}: finish")
  #end
  define_handler(:write_byte) do |context, byte|
    begin
      @io.putc(byte)
      0
    rescue => e
      $stderr.puts("#{e} in #{self.class}#write_byte")
      1
    end
  end
  define_handler(:write_bytes) do |context, data, size, nmemb|
    begin
      @io.write(data.read_string(size * nmemb))
      0
    rescue => e
      $stderr.puts("#{e} in #{self.class}#write_bytes")
      1
    end
  end
  #define_handler(:write_end) do |context|
  #  $stderr.puts("#{self.class}: write_end")
  #end
  #define_handler(:read_bytes) do |context, data, size, nmemb|
  #  $stderr.puts("#{self.class}: read_bytes")
  #end
  #define_handler(:read_eof) do |context|
  #  $stderr.puts("#{self.class}: read_eof")
  #end
end
read_bytes=(func)
Alias for: read_bytes_handler=
read_bytes_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 130
def read_bytes_handler=(func)
  define_handler(:read_bytes, &func)
end
Also aliased as: read_bytes=
read_eof=(func)
Alias for: read_eof_handler=
read_eof_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 138
def read_eof_handler=(func)
  define_handler(:read_eof, &func)
end
Also aliased as: read_eof=
write_byte=(func)
Alias for: write_byte_handler=
write_byte_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 106
def write_byte_handler=(func)
  define_handler(:write_byte, &func)
end
Also aliased as: write_byte=
write_bytes=(func)
write_bytes_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 114
def write_bytes_handler=(func)
  define_handler(:write_bytes, &func)
end
Also aliased as: write_bytes=
write_end=(func)
Alias for: write_end_handler=
write_end_handler=(func) click to toggle source

@param [Proc] func @return [void]

# File lib/rdf/raptor/ffi/v2/iostream_handler.rb, line 122
def write_end_handler=(func)
  define_handler(:write_end, &func)
end
Also aliased as: write_end=