class IOStreams::Reader
Attributes
input_stream[R]
Public Class Methods
file(file_name, original_file_name: file_name, **args, &block)
click to toggle source
When a Writer
supports streams, also allow it to simply support a file
# 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
new(input_stream)
click to toggle source
# File lib/io_streams/reader.rb, line 24 def initialize(input_stream) @input_stream = input_stream end
open(file_name_or_io, **args, &block)
click to toggle source
For processing by either a file name or an open IO stream.
# 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)
click to toggle source
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.
# 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