Module: R509::IOHelpers
- Included in:
- CRL::Administrator, CRL::FileReaderWriter, 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
-
.read_data(filename_or_io) ⇒ Object
Reads data from an IO or file.
-
.write_data(filename_or_io, data, mode = 'wb:ascii-8bit') ⇒ Object
Writes data into an IO or file.
Instance Method Summary collapse
-
#read_data(filename_or_io) ⇒ Object
Reads data from an IO or file.
-
#write_data(filename_or_io, data, mode = 'wb:ascii-8bit') ⇒ Object
Writes data into an IO or file.
Class Method Details
.read_data(filename_or_io) ⇒ Object
Reads data from an IO or file
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/r509/io_helpers.rb', line 29 def self.read_data(filename_or_io) if filename_or_io.respond_to?(:read) if filename_or_io.is_a?(StringIO) filename_or_io.rewind end filename_or_io.read else return File.open(filename_or_io, 'rb:ascii-8bit') do |f| f.read end end end |
.write_data(filename_or_io, data, mode = 'wb:ascii-8bit') ⇒ Object
Writes data into an IO or file
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/r509/io_helpers.rb', line 10 def self.write_data(filename_or_io, data, mode = 'wb:ascii-8bit') if filename_or_io.respond_to?(:write) if filename_or_io.is_a?(StringIO) && mode != "a:ascii-8bit" # Writing to a StringIO in a non-append mode. This requires # us to rewind and truncate it first. filename_or_io.rewind filename_or_io.truncate(0) end filename_or_io.write(data) else return File.open(filename_or_io, mode) do |f| f.write(data) end end end |
Instance Method Details
#read_data(filename_or_io) ⇒ Object
Reads data from an IO or file
53 54 55 |
# File 'lib/r509/io_helpers.rb', line 53 def read_data(filename_or_io) IOHelpers.read_data(filename_or_io) end |
#write_data(filename_or_io, data, mode = 'wb:ascii-8bit') ⇒ Object
Writes data into an IO or file
46 47 48 |
# File 'lib/r509/io_helpers.rb', line 46 def write_data(filename_or_io, data, mode = 'wb:ascii-8bit') IOHelpers.write_data(filename_or_io, data, mode) end |