Class: RDF::Raptor::FFI::V2::IOStreamHandler
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- RDF::Raptor::FFI::V2::IOStreamHandler
- Includes:
- RDF::Raptor::FFI
- Defined in:
- lib/rdf/raptor/ffi/v2/iostream_handler.rb
Overview
Constant Summary collapse
- HANDLERS =
[:init, :finish, :write_byte, :write_bytes, :read_bytes, :read_eof]
Constants included from RDF::Raptor::FFI
Instance Attribute Summary collapse
-
#io ⇒ IO
The IO object to operate upon.
Instance Method Summary collapse
- #define_handler(name, &block)
- #finish_handler=(func) (also: #finish=)
- #init_handler=(func) (also: #init=)
-
#initialize(ptr_or_io = nil) ⇒ IOStreamHandler
constructor
A new instance of IOStreamHandler.
- #initialize!
- #read_bytes_handler=(func) (also: #read_bytes=)
- #read_eof_handler=(func) (also: #read_eof=)
- #write_byte_handler=(func) (also: #write_byte=)
- #write_bytes_handler=(func) (also: #write_bytes=)
- #write_end_handler=(func) (also: #write_end=)
Methods included from RDF::Raptor::FFI
Constructor Details
#initialize(ptr) ⇒ IOStreamHandler #initialize(io) ⇒ IOStreamHandler
Returns a new instance of IOStreamHandler.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |
Instance Attribute Details
#io ⇒ IO
The IO object to operate upon.
21 22 23 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 21 def io @io end |
Instance Method Details
#define_handler(name, &block)
This method returns an undefined value.
146 147 148 149 150 151 |
# 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_handler=(func) Also known as: finish=
This method returns an undefined value.
98 99 100 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 98 def finish_handler=(func) define_handler(:finish, &func) end |
#init_handler=(func) Also known as: init=
This method returns an undefined value.
90 91 92 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 90 def init_handler=(func) define_handler(:init, &func) end |
#initialize!
This method returns an undefined value.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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_handler=(func) Also known as: read_bytes=
This method returns an undefined value.
130 131 132 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 130 def read_bytes_handler=(func) define_handler(:read_bytes, &func) end |
#read_eof_handler=(func) Also known as: read_eof=
This method returns an undefined value.
138 139 140 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 138 def read_eof_handler=(func) define_handler(:read_eof, &func) end |
#write_byte_handler=(func) Also known as: write_byte=
This method returns an undefined value.
106 107 108 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 106 def write_byte_handler=(func) define_handler(:write_byte, &func) end |
#write_bytes_handler=(func) Also known as: write_bytes=
This method returns an undefined value.
114 115 116 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 114 def write_bytes_handler=(func) define_handler(:write_bytes, &func) end |
#write_end_handler=(func) Also known as: write_end=
This method returns an undefined value.
122 123 124 |
# File 'lib/rdf/raptor/ffi/v2/iostream_handler.rb', line 122 def write_end_handler=(func) define_handler(:write_end, &func) end |