Object
A class for managing data buffers.
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
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
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
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
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
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
Return the encoding of the underlying data.
# File lib/gpgme.rb, line 871 def encoding GPGME::gpgme_data_get_encoding(self) end
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 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
Generated with the Darkfish Rdoc Generator 2.