Class: GPGME::IOCallbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/gpgme/io_callbacks.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ IOCallbacks

Returns a new instance of IOCallbacks.



3
4
5
# File 'lib/gpgme/io_callbacks.rb', line 3

def initialize(io)
  @io = io
end

Instance Method Details

#read(hook, length) ⇒ Object



7
8
9
# File 'lib/gpgme/io_callbacks.rb', line 7

def read(hook, length)
  @io.read(length)
end

#seek(hook, offset, whence) ⇒ Object



20
21
22
23
24
# File 'lib/gpgme/io_callbacks.rb', line 20

def seek(hook, offset, whence)
  return @io.pos if offset == 0 && whence == IO::SEEK_CUR
  @io.seek(offset, whence)
  @io.pos
end

#write(hook, buffer, length) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/gpgme/io_callbacks.rb', line 11

def write(hook, buffer, length)
  data = buffer[0 .. length]
  # Handle encoding conversion if the IO has a different encoding
  if @io.respond_to?(:external_encoding) && @io.external_encoding
    data = data.encode(@io.external_encoding, invalid: :replace, undef: :replace)
  end
  @io.write(data)
end