Module: R509::IOHelpers

Included in:
CRL::Administrator, CRL::SignedList, CSR, Cert, Config::CAConfig, Config::CAConfig, PrivateKey, SPKI
Defined in:
lib/r509/io_helpers.rb

Overview

helper methods for I/O

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) read_data(filename_or_io)

Reads data from an IO or file

Parameters:

  • filename_or_io (String, #read)

    Either a string of the path for the file that you'd like to read, or an IO-like object.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/r509/io_helpers.rb', line 24

def self.read_data(filename_or_io)
  if filename_or_io.respond_to?(:read)
    filename_or_io.read()
  else
    begin
      file = File.open(filename_or_io, 'rb:ascii-8bit')
      return file.read()
    ensure
      file.close() unless file.nil?
    end
  end
end

+ (Object) write_data(filename_or_io, data)

Writes data into an IO or file

Parameters:

  • filename_or_io (String, #write)

    Either a string of the path for the file that you'd like to write, or an IO-like object.

  • data (String)

    The data that we want to write



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/r509/io_helpers.rb', line 8

def self.write_data(filename_or_io, data)
  if filename_or_io.respond_to?(:write)
    filename_or_io.write(data)
  else
    begin
      file = File.open(filename_or_io, 'wb:ascii-8bit')
      return file.write(data)
    ensure
      file.close()
    end
  end
end

Instance Method Details

- (Object) read_data(filename_or_io)

Reads data from an IO or file

Parameters:

  • filename_or_io (String, #read)

    Either a string of the path for the file that you'd like to read, or an IO-like object.



48
49
50
# File 'lib/r509/io_helpers.rb', line 48

def read_data(filename_or_io)
  IOHelpers.read_data(filename_or_io)
end

- (Object) write_data(filename_or_io, data)

Writes data into an IO or file

Parameters:

  • filename_or_io (String, #write)

    Either a string of the path for the file that you'd like to write, or an IO-like object.

  • data (String)

    The data that we want to write



41
42
43
# File 'lib/r509/io_helpers.rb', line 41

def write_data(filename_or_io, data)
  IOHelpers.write_data(filename_or_io, data)
end