Sha256: 5bed52b2c7d3d0ac02db95a51633212596b288772d0c9e7c2f0f9dc597a0755e

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 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 '.open' do
      it 'reads the first file' do
        result = IOStreams::Zip::Reader.open(file_name) do |io|
          io.read
        end
        assert_equal decompressed, result
      end

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

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

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iostreams-0.20.3 test/zip_reader_test.rb
iostreams-0.20.2 test/zip_reader_test.rb