Module: FFI::Libfuse::IO
- Defined in:
- lib/ffi/libfuse/io.rb
Overview
Helpers for reading/writing to io like objects
Class Method Summary collapse
-
.read(io, size, offset = nil) ⇒ String
Helper to convert a ruby object to size bytes required by FuseOperations#read.
-
.write(io, data, offset = nil) ⇒ Integer
Helper to write date to IO or String like objects for use with #FuseOperations#write.
Class Method Details
.read(io, size, offset = nil) ⇒ String
Helper to convert a ruby object to size bytes required by FuseOperations#read
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ffi/libfuse/io.rb', line 18 def read(io, size, offset = nil) return io.pread(size, offset) if offset && io.respond_to?(:pread) if (offset ? %i[seek read] : %i[read]).all? { |m| io.respond_to?(m) } io.seek(offset) if offset return io.read(size) end io.to_s[offset || 0, size] || '' end |
.write(io, data, offset = nil) ⇒ Integer
Helper to write date to IO or String like objects for use with #FuseOperations#write
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ffi/libfuse/io.rb', line 40 def write(io, data, offset = nil) if offset && io.respond_to?(:pwrite) io.pwrite(data, offset) elsif (offset ? %i[seek write] : %i[write]).all? { |m| io.respond_to?(m) } io.seek(offset) if offset io.write(data) elsif io.respond_to?(:[]=) # eg String io[offset || 0, data.size] = data data.size else raise "cannot :pwrite or :write to #{io}", Errno::EBADF end end |