class GPGME::Data
methods.
Read the {#read}, {#write} and {#seek} methods for the most commonly used
to create one from your parameters.
and output). Most of the calls expect instances of this class, or will try
A class whose purpose is to unify the way we work with the data (both input
#
def empty!
def empty! rdh = [] err = GPGME::gpgme_data_new(rdh) exc = GPGME::error_to_exception(err) raise exc if exc rdh.first end
def encoding
#
def encoding GPGME::gpgme_data_get_encoding(self) end
def encoding=(encoding)
-
(GPGME::Error::InvalidValue)
- if the value isn't accepted.
def encoding=(encoding) err = GPGME::gpgme_data_set_encoding(self, encoding) exc = GPGME::error_to_exception(err) raise exc if exc encoding end
def file_name
#
def file_name GPGME::gpgme_data_get_file_name(self) end
def file_name=(file_name)
-
(GPGME::Error::InvalidValue)
- if the value isn't accepted.
def file_name=(file_name) err = GPGME::gpgme_data_set_file_name(self, file_name) exc = GPGME::error_to_exception(err) raise exc if exc file_name end
def from_callbacks(callbacks, hook_value = nil)
def from_callbacks(callbacks, hook_value = nil) rdh = [] err = GPGME::gpgme_data_new_from_cbs(rdh, callbacks, hook_value) exc = GPGME::error_to_exception(err) raise exc if exc rdh.first end
def from_fd(fd)
def from_fd(fd) rdh = [] err = GPGME::gpgme_data_new_from_fd(rdh, fd) exc = GPGME::error_to_exception(err) raise exc if exc rdh.first end
def from_io(io)
def from_io(io) from_callbacks(IOCallbacks.new(io)) end
def from_str(string)
def from_str(string) rdh = [] err = GPGME::gpgme_data_new_from_mem(rdh, string, string.bytesize) exc = GPGME::error_to_exception(err) raise exc if exc rdh.first end
def new(object = nil)
- Example: from a file descriptor -
Example: from a file -
Example: from a string -
Example: empty -
def new(object = nil) if object.nil? empty! elsif object.is_a?(Data) object elsif object.is_a?(Integer) from_fd(object) elsif object.respond_to? :to_str from_str(object.to_str) elsif object.respond_to? :to_io from_io(object.to_io) elsif object.respond_to? :open from_io(object.open) elsif defined?(StringIO) and object.is_a?(StringIO) from_io(object) end end
def read(length = nil)
data.read(4) # => "From"
data = GPGME::Data.new("From a string")
@example
data.read # => "From a string"
data = GPGME::Data.new("From a string")
@example
of file if +length+ is omitted or is +nil+.
Read at most +length+ bytes from the data object, or to the end
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
def seek(offset, whence = IO::SEEK_SET)
- Example: going to the beginning of the buffer after writing something -
def seek(offset, whence = IO::SEEK_SET) GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET) end
def to_s
#
def to_s pos = seek(0, IO::SEEK_CUR) begin seek(0) read ensure seek(pos) end end
def write(buffer, length = buffer.length)
data.read # => "ho"
data.seek 0
data.write "hola", 2
data = GPGME::Data.new
@example
data.read # => "hola"
data.seek 0
data.write "hola"
data = GPGME::Data.new
@example
Writes the full buffer if no length passed.
Writes +length+ bytes from +buffer+ into the data object.
#
def write(buffer, length = buffer.length) GPGME::gpgme_data_write(self, buffer, length) end