Sha256: 13278ef10800a8ed11b66a11bfc3c33e2e17443b642015e4051f36cd9fdb280e

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

require_relative '../spec_helper'

describe ZipTricks::RackBody do
  it 'is usable as a Rack response body, supports each() and close()' do
    output_buf = Tempfile.new('output')
    
    file_body = SecureRandom.random_bytes(1024 * 1024 + 8981)
    
    body = described_class.new do | zip |
      zip.add_stored_entry("A file", file_body.bytesize, Zlib.crc32(file_body))
      zip << file_body
    end
    
    body.each do | some_data |
      output_buf << some_data
    end
    body.close
    
    output_buf.rewind
    expect(output_buf.size).to eq(1057667)
    
    per_filename = {}
    Zip::File.open(output_buf.path) do |zip_file|
      # Handle entries one by one
      zip_file.each do |entry|
        # The entry name gets returned with a binary encoding, we have to force it back.
        per_filename[entry.name] = entry.get_input_stream.read
      end
    end
    
    expect(per_filename).to have_key('A file')
    expect(per_filename['A file'].bytesize).to eq(file_body.bytesize)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zip_tricks-2.6.0 spec/zip_tricks/rack_body_spec.rb
zip_tricks-2.5.0 spec/zip_tricks/rack_body_spec.rb