In Files

Parent

GPGME::Data

A class for managing data buffers.

Constants

BLOCK_SIZE

Public Class Methods

empty() click to toggle source

Create a new instance with an empty buffer.

# File lib/gpgme.rb, line 803
def self.empty
  rdh = Array.new
  err = GPGME::gpgme_data_new(rdh)
  exc = GPGME::error_to_exception(err)
  raise exc if exc
  rdh[0]
end
from_callbacks(callbacks, hook_value = nil) click to toggle source

Create a new instance from the specified callbacks.

# File lib/gpgme.rb, line 835
def self.from_callbacks(callbacks, hook_value = nil)
  rdh = Array.new
  err = GPGME::gpgme_data_new_from_cbs(rdh, callbacks, hook_value)
  exc = GPGME::error_to_exception(err)
  raise exc if exc
  rdh[0]
end
from_fd(fd) click to toggle source

Create a new instance from the specified file descriptor.

# File lib/gpgme.rb, line 826
def self.from_fd(fd)
  rdh = Array.new
  err = GPGME::gpgme_data_new_from_fd(rdh, fd)
  exc = GPGME::error_to_exception(err)
  raise exc if exc
  rdh[0]
end
from_io(io) click to toggle source

Create a new instance associated with a given IO.

# File lib/gpgme.rb, line 821
def self.from_io(io)
  from_callbacks(IOCallbacks.new(arg))
end
from_str(buf, copy = true) click to toggle source

Create a new instance with internal buffer.

# File lib/gpgme.rb, line 812
def self.from_str(buf, copy = true)
  rdh = Array.new
  err = GPGME::gpgme_data_new_from_mem(rdh, buf, buf.length)
  exc = GPGME::error_to_exception(err)
  raise exc if exc
  rdh[0]
end
new(arg = nil, copy = false) click to toggle source

Create a new instance.

The created data types depend on arg. If arg is nil, it creates an instance with an empty buffer. Otherwise, arg is either a string, an IO, or a Pathname.

# File lib/gpgme.rb, line 790
def self.new(arg = nil, copy = false)
  if arg.nil?
    return empty
  elsif arg.respond_to? :to_str
    return from_str(arg.to_str, copy)
  elsif arg.respond_to? :to_io
    return from_io(arg.to_io)
  elsif arg.respond_to? :open
    return from_io(arg.open)
  end
end

Public Instance Methods

encoding() click to toggle source

Return the encoding of the underlying data.

# File lib/gpgme.rb, line 871
def encoding
  GPGME::gpgme_data_get_encoding(self)
end
encoding=(encoding) click to toggle source

Set the encoding to a given encoding of the underlying data object.

# File lib/gpgme.rb, line 877
def encoding=(encoding)
  err = GPGME::gpgme_data_set_encoding(self, encoding)
  exc = GPGME::error_to_exception(err)
  raise exc if exc
  encoding
end
read(length = nil) click to toggle source

Read at most length bytes from the data object, or to the end of file if length is omitted or is nil.

# File lib/gpgme.rb, line 845
def read(length = nil)
  if length
    GPGME::gpgme_data_read(self, length)
  else
    buf = String.new
    loop do
      s = GPGME::gpgme_data_read(self, BLOCK_SIZE)
      break unless s
      buf << s
    end
    buf
  end
end
seek(offset, whence = IO::SEEK_SET) click to toggle source

Seek to a given offset in the data object according to the value of whence.

# File lib/gpgme.rb, line 861
def seek(offset, whence = IO::SEEK_SET)
  GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET)
end
write(buffer, length = buffer.length) click to toggle source

Write length bytes from buffer into the data object.

# File lib/gpgme.rb, line 866
def write(buffer, length = buffer.length)
  GPGME::gpgme_data_write(self, buffer, length)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.