Class: IOStreams::Reader
- Inherits:
-
Object
- Object
- IOStreams::Reader
- Defined in:
- lib/io_streams/reader.rb
Direct Known Subclasses
Bzip2::Reader, Encode::Reader, Gzip::Reader, Line::Reader, Pgp::Reader, IOStreams::Record::Reader, IOStreams::Row::Reader, SymmetricEncryption::Reader, Xlsx::Reader, Zip::Reader
Instance Attribute Summary collapse
-
#input_stream ⇒ Object
readonly
Returns the value of attribute input_stream.
Class Method Summary collapse
-
.file(file_name, original_file_name: file_name, **args, &block) ⇒ Object
When a Writer supports streams, also allow it to simply support a file.
-
.open(file_name_or_io, **args, &block) ⇒ Object
For processing by either a file name or an open IO stream.
-
.stream(input_stream, **args, &block) ⇒ Object
When a Reader does not support streams, we copy the stream to a local temp file and then pass that filename in for this reader.
Instance Method Summary collapse
-
#initialize(input_stream) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(input_stream) ⇒ Reader
Returns a new instance of Reader.
24 25 26 |
# File 'lib/io_streams/reader.rb', line 24 def initialize(input_stream) @input_stream = input_stream end |
Instance Attribute Details
#input_stream ⇒ Object (readonly)
Returns the value of attribute input_stream.
22 23 24 |
# File 'lib/io_streams/reader.rb', line 22 def input_stream @input_stream end |
Class Method Details
.file(file_name, original_file_name: file_name, **args, &block) ⇒ Object
When a Writer supports streams, also allow it to simply support a file
13 14 15 |
# File 'lib/io_streams/reader.rb', line 13 def self.file(file_name, original_file_name: file_name, **args, &block) ::File.open(file_name, "rb") { |file| stream(file, original_file_name: original_file_name, **args, &block) } end |
.open(file_name_or_io, **args, &block) ⇒ Object
For processing by either a file name or an open IO stream.
18 19 20 |
# File 'lib/io_streams/reader.rb', line 18 def self.open(file_name_or_io, **args, &block) file_name_or_io.is_a?(String) ? file(file_name_or_io, **args, &block) : stream(file_name_or_io, **args, &block) end |
.stream(input_stream, **args, &block) ⇒ Object
When a Reader does not support streams, we copy the stream to a local temp file and then pass that filename in for this reader.
5 6 7 8 9 10 |
# File 'lib/io_streams/reader.rb', line 5 def self.stream(input_stream, **args, &block) Utils.temp_file_name("iostreams_reader") do |file_name| ::File.open(file_name, "wb") { |target| ::IO.copy_stream(input_stream, target) } file(file_name, **args, &block) end end |