Sha256: 56ea25a3040e1543dfc05c597bfdb4206fe1f90285ba33296657ed04cb23b74e

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require_relative 'test_helper'
require 'zip'

class ZipWriterTest < Minitest::Test
  describe IOStreams::Zip::Writer do
    let :temp_file do
      Tempfile.new('iostreams')
    end

    let :file_name do
      temp_file.path
    end

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

    after do
      temp_file.delete
    end

    describe '.file' do
      it 'file' do
        IOStreams::Zip::Writer.file(file_name, entry_file_name: 'text.txt') do |io|
          io.write(decompressed)
        end
        result = ::Zip::File.open(file_name) do |zip_file|
          zip_file.first.get_input_stream.read
        end
        assert_equal decompressed, result
      end

      it 'stream' do
        io_string = StringIO.new(''.b)
        IOStreams::Zip::Writer.stream(io_string) do |io|
          io.write(decompressed)
        end
        io     = StringIO.new(io_string.string)
        result = nil
        begin
          zin = ::Zip::InputStream.new(io)
          zin.get_next_entry
          result = zin.read
        ensure
          zin.close if zin
        end
        assert_equal decompressed, result
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iostreams-1.0.0.beta5 test/zip_writer_test.rb
iostreams-1.0.0.beta4 test/zip_writer_test.rb
iostreams-1.0.0.beta3 test/zip_writer_test.rb
iostreams-1.0.0.beta2 test/zip_writer_test.rb
iostreams-1.0.0.beta test/zip_writer_test.rb