Sha256: 7c2fb48cd4e0127de99867c4329fc5ff3f8be402b8456acf5fee94da01c5d60c

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

module IOStreams
  class Reader
    # 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.
    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

    # When a Writer supports streams, also allow it to simply support a file
    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

    # For processing by either a file name or an open IO stream.
    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

    attr_reader :input_stream

    def initialize(input_stream)
      @input_stream = input_stream
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
iostreams-1.10.3 lib/io_streams/reader.rb
iostreams-1.10.2 lib/io_streams/reader.rb
iostreams-1.10.1 lib/io_streams/reader.rb
iostreams-1.10.0 lib/io_streams/reader.rb
iostreams-1.9.0 lib/io_streams/reader.rb
iostreams-1.8.0 lib/io_streams/reader.rb
iostreams-1.7.0 lib/io_streams/reader.rb
iostreams-1.6.2 lib/io_streams/reader.rb
iostreams-1.6.1 lib/io_streams/reader.rb
iostreams-1.6.0 lib/io_streams/reader.rb
iostreams-1.5.1 lib/io_streams/reader.rb
iostreams-1.5.0 lib/io_streams/reader.rb
iostreams-1.4.0 lib/io_streams/reader.rb
iostreams-1.3.3 lib/io_streams/reader.rb
iostreams-1.3.2 lib/io_streams/reader.rb
iostreams-1.3.1 lib/io_streams/reader.rb
iostreams-1.3.0 lib/io_streams/reader.rb
iostreams-1.2.1 lib/io_streams/reader.rb
iostreams-1.2.0 lib/io_streams/reader.rb
iostreams-1.1.1 lib/io_streams/reader.rb