Sha256: 793344824ad33596311bc6a0d5c92bf7ee6dc0eecacc52427534f950f0f1ba27

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 KB

Contents

require_relative "test_helper"
require_relative "minimal_file_reader"
require "zip"

class ZipReaderTest < Minitest::Test
  describe IOStreams::Zip::Reader do
    let :file_name do
      File.join(File.dirname(__FILE__), "files", "text.zip")
    end

    let :multiple_zip_file_name do
      File.join(File.dirname(__FILE__), "files", "multiple_files.zip")
    end

    let :contents_test_txt do
      File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
    end

    let :contents_test_json do
      File.read(File.join(File.dirname(__FILE__), "files", "test.json"))
    end

    let :decompressed do
      Zip::File.open(file_name) { |zip_file| zip_file.first.get_input_stream.read }
    end

    describe ".file" do
      it "reads the first file" do
        result = IOStreams::Zip::Reader.file(file_name, &:read)
        assert_equal decompressed, result
      end

      it "reads entry within zip file" do
        result = IOStreams::Zip::Reader.file(multiple_zip_file_name, entry_file_name: "text.txt", &:read)
        assert_equal contents_test_txt, result
      end

      it "reads another entry within zip file" do
        result = IOStreams::Zip::Reader.file(multiple_zip_file_name, entry_file_name: "test.json", &:read)
        assert_equal contents_test_json, result
      end

      # it 'reads from a stream' do
      #   result = MinimalFileReader.open(file_name) do |file|
      #     IOStreams::Zip::Reader.stream(file) do |io|
      #       io.read
      #     end
      #   end
      #   assert_equal decompressed, result
      # end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

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