Sha256: 1c038b4b09ba1cb4f4cac222bc7d6f62a6e50f57f1aedeeccf5f799e472c4bba

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require_relative '../spec_helper'

describe 'Microzip in interop context' do
  let(:described_class) { ZipTricks::Microzip}
  
  it 'creates an archive that can be opened by Rubyzip, with a small number of very tiny text files' do
    tf = ManagedTempfile.new('zip')
    z = described_class.new

    test_str = Random.new.bytes(64)
    crc = Zlib.crc32(test_str)
    t = Time.now.utc

    3.times do |i|
      fn = "test-#{i}"
      z.add_local_file_header(io: tf, filename: fn, crc32: crc, compressed_size: test_str.bytesize,
        uncompressed_size: test_str.bytesize, storage_mode: 0, mtime: t)
      tf << test_str
    end
    z.write_central_directory(tf)
    tf.flush

    Zip::File.open(tf.path) do |zip_file|
      entries = zip_file.to_a
      expect(entries.length).to eq(3)
      entries.each do |entry|
        # Make sure it is tagged as UNIX
        expect(entry.fstype).to eq(3)

        # Check the file contents
        readback = entry.get_input_stream.read
        readback.force_encoding(Encoding::BINARY)
        expect(readback).to eq(test_str)

        # The CRC
        expect(entry.crc).to eq(crc)

        # Check the name
        expect(entry.name).to match(/test/)

        # Check the right external attributes (non-executable on UNIX)
        expect(entry.external_file_attributes).to eq(2175008768)
      end
    end

    inspect_zip_with_external_tool(tf.path)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zip_tricks-2.8.1 spec/zip_tricks/microzip_interop_spec.rb
zip_tricks-2.8.0 spec/zip_tricks/microzip_interop_spec.rb