Class GPGME::Data
In: lib/gpgme/data.rb
ext/gpgme/gpgme_n.c
Parent: Object

The CTX argument can be `NULL’. In that case, `gpgme_wait’ waits

  for any context to complete its operation.

Methods

empty!   encoding   encoding=   from_callbacks   from_fd   from_io   from_str   new   read   seek   to_s   write  

Constants

BLOCK_SIZE = 4096

Public Class methods

Create a new instance with an empty buffer.

Create a new instance from the specified callbacks.

Create a new instance from the specified file descriptor.

Create a new instance associated with a given IO.

Create a new instance with internal buffer.

We implement +self.new+ instead of initialize because objects are actually instantiated through the C API with stuff like gpgme_data_new.

We try to create a {GPGME::Data} smartly depending on the object passed, and if another {GPGME::Data} object is passed, it just returns it, so when in doubt, you can always pass a {GPGME::Data} object.

@example empty

  data = GPGME::Data.new
  data.write("stuff")

@example from a string

  data = GPGME::Data.new("From a string")

@example from a file

  data = GPGME::Data.new(File.open("secure.pass"))

@example from a file descriptor

  data = GPGME::Data.new(0) # Standard input
  data = GPGME::Data.new(1) # Standard output

  file = File.open("secure.pass")
  data = GPGME::Data.new(file.fileno) # file descriptor

Public Instance methods

Return the encoding of the underlying data.

Sets the encoding for this buffer. Accepts only values in one of the DATA_ENCODING_* constants.

@raise [GPGME::Error::InvalidValue] if the value isn‘t accepted.

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

@example

  data = GPGME::Data.new("From a string")
  data.read # => "From a string"

@example

  data = GPGME::Data.new("From a string")
  data.read(4) # => "From"

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

@example going to the beginning of the buffer after writing something

 data = GPGME::Data.new("Some data")
 data.read # => "Some data"
 data.read # => ""
 data.seek 0
 data.read # => "Some data"

Return the entire content of the data object as string.

Writes length bytes from buffer into the data object. Writes the full buffer if no length passed.

@example

  data = GPGME::Data.new
  data.write "hola"
  data.seek 0
  data.read # => "hola"

@example

  data = GPGME::Data.new
  data.write "hola", 2
  data.seek 0
  data.read # => "ho"

[Validate]