Use keyword arguments for the `Entry` initializer.
This greatly simplifies the creation of `Entry` objects when only a couple of fields are not set to their defaults, while at the same time allowing an `Entry` to be fully configured at creation time if appropriate. This fundamentally changes the `Entry` API and means that some convenience methods in `OutputStream` and `File` have needed to be refactored.
This commit is contained in:
parent
2775f529b4
commit
e4ceedaa58
|
@ -52,26 +52,32 @@ module Zip
|
|||
raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
@name = args[1] || ''
|
||||
def initialize(
|
||||
zipfile = '', name = '',
|
||||
comment: '', size: 0, compressed_size: 0, crc: 0,
|
||||
compression_method: DEFLATED,
|
||||
compression_level: ::Zip.default_compression,
|
||||
time: ::Zip::DOSTime.now, extra: ::Zip::ExtraField.new
|
||||
)
|
||||
@name = name
|
||||
check_name(@name)
|
||||
|
||||
set_default_vars_values
|
||||
@fstype = ::Zip::RUNNING_ON_WINDOWS ? ::Zip::FSTYPE_FAT : ::Zip::FSTYPE_UNIX
|
||||
@ftype = name_is_directory? ? :directory : :file
|
||||
|
||||
@zipfile = args[0] || ''
|
||||
@comment = args[2] || ''
|
||||
@extra = args[3] || ''
|
||||
@compressed_size = args[4] || 0
|
||||
@crc = args[5] || 0
|
||||
@compression_method =
|
||||
(@ftype == :directory ? STORED : args[6] || DEFLATED)
|
||||
@compression_level = args[7] || ::Zip.default_compression
|
||||
@size = args[8] || 0
|
||||
@time = args[9] || ::Zip::DOSTime.now
|
||||
@zipfile = zipfile
|
||||
@comment = comment
|
||||
@compression_method = compression_method
|
||||
@compression_level = compression_level
|
||||
|
||||
@compressed_size = compressed_size
|
||||
@crc = crc
|
||||
@size = size
|
||||
@time = time
|
||||
@extra =
|
||||
extra.kind_of?(ExtraField) ? extra : ExtraField.new(extra.to_s)
|
||||
|
||||
@extra = ::Zip::ExtraField.new(@extra.to_s) unless @extra.kind_of?(::Zip::ExtraField)
|
||||
set_compression_level_flags
|
||||
end
|
||||
|
||||
|
|
|
@ -276,7 +276,12 @@ module Zip
|
|||
if entry.kind_of?(Entry)
|
||||
entry
|
||||
else
|
||||
Entry.new(@name, entry.to_s, comment, extra, compressed_size, crc, compression_method, compression_level, size, time)
|
||||
Entry.new(
|
||||
@name, entry.to_s, comment: comment, extra: extra,
|
||||
compressed_size: compressed_size, crc: crc, size: size,
|
||||
compression_method: compression_method,
|
||||
compression_level: compression_level, time: time
|
||||
)
|
||||
end
|
||||
if new_entry.directory?
|
||||
raise ArgumentError,
|
||||
|
@ -305,7 +310,10 @@ module Zip
|
|||
new_entry = if entry.kind_of?(::Zip::Entry)
|
||||
entry
|
||||
else
|
||||
::Zip::Entry.new(@name, entry.to_s, nil, nil, 0, 0, ::Zip::Entry::DEFLATED, @compression_level)
|
||||
::Zip::Entry.new(
|
||||
@name, entry.to_s,
|
||||
compression_level: @compression_level
|
||||
)
|
||||
end
|
||||
new_entry.gather_fileinfo_from_srcpath(src_path)
|
||||
new_entry.dirty = true
|
||||
|
@ -315,7 +323,9 @@ module Zip
|
|||
# Convenience method for adding the contents of a file to the archive
|
||||
# in Stored format (uncompressed)
|
||||
def add_stored(entry, src_path, &continue_on_exists_proc)
|
||||
entry = ::Zip::Entry.new(@name, entry.to_s, nil, nil, nil, nil, ::Zip::Entry::STORED)
|
||||
entry = ::Zip::Entry.new(
|
||||
@name, entry.to_s, compression_method: ::Zip::Entry::STORED
|
||||
)
|
||||
add(entry, src_path, &continue_on_exists_proc)
|
||||
end
|
||||
|
||||
|
|
|
@ -89,13 +89,20 @@ module Zip
|
|||
|
||||
# Closes the current entry and opens a new for writing.
|
||||
# +entry+ can be a ZipEntry object or a string.
|
||||
def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression)
|
||||
def put_next_entry(
|
||||
entry_name, comment = '', extra = ExtraField.new,
|
||||
compression_method = Entry::DEFLATED, level = Zip.default_compression
|
||||
)
|
||||
raise Error, 'zip stream is closed' if @closed
|
||||
|
||||
new_entry = if entry_name.kind_of?(Entry)
|
||||
entry_name
|
||||
else
|
||||
Entry.new(@file_name, entry_name.to_s, comment, extra, 0, 0, compression_method, level)
|
||||
Entry.new(
|
||||
@file_name, entry_name.to_s, comment: comment,
|
||||
extra: extra, compression_method: compression_method,
|
||||
compression_level: level
|
||||
)
|
||||
end
|
||||
|
||||
init_next_entry(new_entry)
|
||||
|
|
|
@ -38,9 +38,14 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_write_to_stream
|
||||
entries = [::Zip::Entry.new('file.zip', 'flimse', 'myComment', 'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt', 'Has a comment too')]
|
||||
entries = [
|
||||
::Zip::Entry.new(
|
||||
'file.zip', 'flimse',
|
||||
comment: 'myComment', extra: 'somethingExtra'
|
||||
),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt', comment: 'Has a comment')
|
||||
]
|
||||
|
||||
cdir = ::Zip::CentralDirectory.new(entries, 'my zip comment')
|
||||
File.open('test/data/generated/cdirtest.bin', 'wb') do |f|
|
||||
|
@ -57,10 +62,26 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
|||
|
||||
def test_write64_to_stream
|
||||
::Zip.write_zip64_support = true
|
||||
entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200),
|
||||
::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18_000_000_000, 102, ::Zip::Entry::DEFLATED, 20_000_000_000),
|
||||
::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15_000_000_000, 103, ::Zip::Entry::DEFLATED, 21_000_000_000),
|
||||
::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)]
|
||||
entries = [
|
||||
::Zip::Entry.new(
|
||||
'file.zip', 'file1-little', comment: 'comment1', size: 200,
|
||||
compressed_size: 200, crc: 101,
|
||||
compression_method: ::Zip::Entry::STORED
|
||||
),
|
||||
::Zip::Entry.new(
|
||||
'file.zip', 'file2-big', comment: 'comment2',
|
||||
size: 20_000_000_000, compressed_size: 18_000_000_000, crc: 102
|
||||
),
|
||||
::Zip::Entry.new(
|
||||
'file.zip', 'file3-alsobig', comment: 'comment3',
|
||||
size: 21_000_000_000, compressed_size: 15_000_000_000, crc: 103
|
||||
),
|
||||
::Zip::Entry.new(
|
||||
'file.zip', 'file4-little', comment: 'comment4',
|
||||
size: 121, compressed_size: 100, crc: 104
|
||||
)
|
||||
]
|
||||
|
||||
[0, 250, 18_000_000_300, 33_000_000_350].each_with_index do |offset, index|
|
||||
entries[index].local_header_offset = offset
|
||||
end
|
||||
|
@ -80,25 +101,37 @@ class ZipCentralDirectoryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_equality
|
||||
cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
|
||||
'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')],
|
||||
'my zip comment')
|
||||
cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
|
||||
'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')],
|
||||
'my zip comment')
|
||||
cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
|
||||
'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')],
|
||||
'comment?')
|
||||
cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
|
||||
'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')],
|
||||
'comment?')
|
||||
cdir1 = ::Zip::CentralDirectory.new(
|
||||
[
|
||||
::Zip::Entry.new('file.zip', 'flimse', extra: 'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')
|
||||
],
|
||||
'my zip comment'
|
||||
)
|
||||
cdir2 = ::Zip::CentralDirectory.new(
|
||||
[
|
||||
::Zip::Entry.new('file.zip', 'flimse', extra: 'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')
|
||||
],
|
||||
'my zip comment'
|
||||
)
|
||||
cdir3 = ::Zip::CentralDirectory.new(
|
||||
[
|
||||
::Zip::Entry.new('file.zip', 'flimse', extra: 'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'secondEntryName'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')
|
||||
],
|
||||
'comment?'
|
||||
)
|
||||
cdir4 = ::Zip::CentralDirectory.new(
|
||||
[
|
||||
::Zip::Entry.new('file.zip', 'flimse', extra: 'somethingExtra'),
|
||||
::Zip::Entry.new('file.zip', 'lastEntry.txt')
|
||||
],
|
||||
'comment?'
|
||||
)
|
||||
assert_equal(cdir1, cdir1)
|
||||
assert_equal(cdir1, cdir2)
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ require 'test_helper'
|
|||
|
||||
class ZipEntrySetTest < MiniTest::Test
|
||||
ZIP_ENTRIES = [
|
||||
::Zip::Entry.new('zipfile.zip', 'name1', 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name3', 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name2', 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name4', 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name5', 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name6', 'comment1')
|
||||
::Zip::Entry.new('zipfile.zip', 'name1', comment: 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name3', comment: 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name2', comment: 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name4', comment: 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name5', comment: 'comment1'),
|
||||
::Zip::Entry.new('zipfile.zip', 'name6', comment: 'comment1')
|
||||
]
|
||||
|
||||
def setup
|
||||
|
@ -20,13 +20,17 @@ class ZipEntrySetTest < MiniTest::Test
|
|||
|
||||
def test_include
|
||||
assert(@zip_entry_set.include?(ZIP_ENTRIES.first))
|
||||
assert(!@zip_entry_set.include?(::Zip::Entry.new('different.zip', 'different', 'aComment')))
|
||||
assert(
|
||||
!@zip_entry_set.include?(
|
||||
::Zip::Entry.new('different.zip', 'different', comment: 'aComment')
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def test_size
|
||||
assert_equal(ZIP_ENTRIES.size, @zip_entry_set.size)
|
||||
assert_equal(ZIP_ENTRIES.size, @zip_entry_set.length)
|
||||
@zip_entry_set << ::Zip::Entry.new('a', 'b', 'c')
|
||||
@zip_entry_set << ::Zip::Entry.new('a', 'b', comment: 'c')
|
||||
assert_equal(ZIP_ENTRIES.size + 1, @zip_entry_set.length)
|
||||
end
|
||||
|
||||
|
@ -66,7 +70,9 @@ class ZipEntrySetTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_find_entry
|
||||
entries = [::Zip::Entry.new('zipfile.zip', 'MiXeDcAsEnAmE', 'comment1')]
|
||||
entries = [
|
||||
::Zip::Entry.new('zipfile.zip', 'MiXeDcAsEnAmE', comment: 'comment1')
|
||||
]
|
||||
|
||||
::Zip.case_insensitive_match = true
|
||||
zip_entry_set = ::Zip::EntrySet.new(entries)
|
||||
|
@ -96,7 +102,9 @@ class ZipEntrySetTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_compound
|
||||
new_entry = ::Zip::Entry.new('zf.zip', 'new entry', "new entry's comment")
|
||||
new_entry = ::Zip::Entry.new(
|
||||
'zf.zip', 'new entry', comment: "new entry's comment"
|
||||
)
|
||||
assert_equal(ZIP_ENTRIES.size, @zip_entry_set.size)
|
||||
@zip_entry_set << new_entry
|
||||
assert_equal(ZIP_ENTRIES.size + 1, @zip_entry_set.size)
|
||||
|
|
|
@ -4,16 +4,14 @@ class ZipEntryTest < MiniTest::Test
|
|||
include ZipEntryData
|
||||
|
||||
def test_constructor_and_getters
|
||||
entry = ::Zip::Entry.new(TEST_ZIPFILE,
|
||||
TEST_NAME,
|
||||
TEST_COMMENT,
|
||||
TEST_EXTRA,
|
||||
TEST_COMPRESSED_SIZE,
|
||||
TEST_CRC,
|
||||
TEST_COMPRESSIONMETHOD,
|
||||
TEST_COMPRESSIONLEVEL,
|
||||
TEST_SIZE,
|
||||
TEST_TIME)
|
||||
entry = ::Zip::Entry.new(
|
||||
TEST_ZIPFILE, TEST_NAME,
|
||||
comment: TEST_COMMENT, extra: TEST_EXTRA,
|
||||
compressed_size: TEST_COMPRESSED_SIZE,
|
||||
crc: TEST_CRC, size: TEST_SIZE, time: TEST_TIME,
|
||||
compression_method: TEST_COMPRESSIONMETHOD,
|
||||
compression_level: TEST_COMPRESSIONLEVEL
|
||||
)
|
||||
|
||||
assert_equal(TEST_COMMENT, entry.comment)
|
||||
assert_equal(TEST_COMPRESSED_SIZE, entry.compressed_size)
|
||||
|
@ -40,30 +38,54 @@ class ZipEntryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_equality
|
||||
entry1 = ::Zip::Entry.new('file.zip', 'name', 'isNotCompared',
|
||||
'something extra', 123, 1234,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression, 10_000)
|
||||
entry2 = ::Zip::Entry.new('file.zip', 'name', 'isNotComparedXXX',
|
||||
'something extra', 123, 1234,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression, 10_000)
|
||||
entry3 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
||||
'something extra', 123, 1234,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression, 10_000)
|
||||
entry4 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
||||
'something extraXX', 123, 1234,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression, 10_000)
|
||||
entry5 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
||||
'something extraXX', 12, 1234,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression, 10_000)
|
||||
entry6 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
||||
'something extraXX', 12, 123,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression, 10_000)
|
||||
entry7 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
||||
'something extraXX', 12, 123,
|
||||
::Zip::Entry::STORED, ::Zip.default_compression, 10_000)
|
||||
entry8 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
||||
'something extraXX', 12, 123,
|
||||
::Zip::Entry::STORED, ::Zip.default_compression, 100_000)
|
||||
entry1 = ::Zip::Entry.new(
|
||||
'file.zip', 'name',
|
||||
comment: 'isNotCompared', extra: 'something extra',
|
||||
compressed_size: 123, crc: 1234, size: 10_000
|
||||
)
|
||||
|
||||
entry2 = ::Zip::Entry.new(
|
||||
'file.zip', 'name',
|
||||
comment: 'isNotComparedXXX', extra: 'something extra',
|
||||
compressed_size: 123, crc: 1234, size: 10_000
|
||||
)
|
||||
|
||||
entry3 = ::Zip::Entry.new(
|
||||
'file.zip', 'name2',
|
||||
comment: 'isNotComparedXXX', extra: 'something extra',
|
||||
compressed_size: 123, crc: 1234, size: 10_000
|
||||
)
|
||||
|
||||
entry4 = ::Zip::Entry.new(
|
||||
'file.zip', 'name2',
|
||||
comment: 'isNotComparedXXX', extra: 'something extraXX',
|
||||
compressed_size: 123, crc: 1234, size: 10_000
|
||||
)
|
||||
|
||||
entry5 = ::Zip::Entry.new(
|
||||
'file.zip', 'name2',
|
||||
comment: 'isNotComparedXXX', extra: 'something extraXX',
|
||||
compressed_size: 12, crc: 1234, size: 10_000
|
||||
)
|
||||
|
||||
entry6 = ::Zip::Entry.new(
|
||||
'file.zip', 'name2',
|
||||
comment: 'isNotComparedXXX', extra: 'something extraXX',
|
||||
compressed_size: 12, crc: 123, size: 10_000
|
||||
)
|
||||
|
||||
entry7 = ::Zip::Entry.new(
|
||||
'file.zip', 'name2', comment: 'isNotComparedXXX',
|
||||
extra: 'something extraXX', compressed_size: 12, crc: 123, size: 10_000,
|
||||
compression_method: ::Zip::Entry::STORED
|
||||
)
|
||||
|
||||
entry8 = ::Zip::Entry.new(
|
||||
'file.zip', 'name2',
|
||||
comment: 'isNotComparedXXX', extra: 'something extraXX',
|
||||
compressed_size: 12, crc: 123, size: 100_000,
|
||||
compression_method: ::Zip::Entry::STORED
|
||||
)
|
||||
|
||||
assert_equal(entry1, entry1)
|
||||
assert_equal(entry1, entry2)
|
||||
|
@ -131,13 +153,11 @@ class ZipEntryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
zipfile = Zip::File.open('/tmp/no_compress.zip', Zip::File::CREATE)
|
||||
mimetype_entry = Zip::Entry.new(zipfile, # @zipfile
|
||||
'mimetype', # @name
|
||||
'', # @comment
|
||||
'', # @extra
|
||||
0, # @compressed_size
|
||||
0, # @crc
|
||||
Zip::Entry::STORED) # @comppressed_method
|
||||
mimetype_entry = Zip::Entry.new(
|
||||
zipfile, # @zipfile
|
||||
'mimetype', # @name
|
||||
compression_method: Zip::Entry::STORED
|
||||
)
|
||||
|
||||
zipfile.add(mimetype_entry, 'test/data/mimetype')
|
||||
|
||||
|
@ -182,18 +202,27 @@ class ZipEntryTest < MiniTest::Test
|
|||
[8, 2],
|
||||
[9, 2]
|
||||
].each do |level, flags|
|
||||
# Check flags are set correctly when DEFLATED is specified.
|
||||
e_def = Zip::Entry.new('', '', '', '', 0, 0, Zip::Entry::DEFLATED, level)
|
||||
# Check flags are set correctly when DEFLATED is (implicitly) specified.
|
||||
e_def = Zip::Entry.new(
|
||||
'', '',
|
||||
compression_level: level
|
||||
)
|
||||
assert_equal(flags, e_def.gp_flags & 0b110)
|
||||
|
||||
# Check that flags are not set when STORED is specified.
|
||||
e_sto = Zip::Entry.new('', '', '', '', 0, 0, Zip::Entry::STORED, level)
|
||||
e_sto = Zip::Entry.new(
|
||||
'', '',
|
||||
compression_method: Zip::Entry::STORED,
|
||||
compression_level: level
|
||||
)
|
||||
assert_equal(0, e_sto.gp_flags & 0b110)
|
||||
end
|
||||
|
||||
# Check that a directory entry's flags are not set, even if DEFLATED
|
||||
# is specified.
|
||||
e_dir = Zip::Entry.new('', 'd/', '', '', 0, 0, Zip::Entry::DEFLATED, 1)
|
||||
e_dir = Zip::Entry.new(
|
||||
'', 'd/', compression_method: Zip::Entry::DEFLATED, compression_level: 1
|
||||
)
|
||||
assert_equal(0, e_dir.gp_flags & 0b110)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -77,7 +77,10 @@ class ZipFileTest < MiniTest::Test
|
|||
assert_equal(count + 1, zf.size)
|
||||
assert_equal('Putting stuff in data/generated/empty.txt', zf.read('test/data/generated/empty.txt'))
|
||||
|
||||
custom_entry_args = [TEST_COMMENT, TEST_EXTRA, TEST_COMPRESSED_SIZE, TEST_CRC, ::Zip::Entry::STORED, ::Zlib::BEST_SPEED, TEST_SIZE, TEST_TIME]
|
||||
custom_entry_args = [
|
||||
TEST_COMMENT, TEST_EXTRA, TEST_COMPRESSED_SIZE, TEST_CRC,
|
||||
::Zip::Entry::STORED, ::Zlib::BEST_SPEED, TEST_SIZE, TEST_TIME
|
||||
]
|
||||
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
|
||||
os.write 'Some data'
|
||||
end
|
||||
|
|
|
@ -53,9 +53,11 @@ class ZipLocalEntryTest < MiniTest::Test
|
|||
end
|
||||
|
||||
def test_write_entry
|
||||
entry = ::Zip::Entry.new('file.zip', 'entry_name', 'my little comment',
|
||||
'thisIsSomeExtraInformation', 100, 987_654,
|
||||
::Zip::Entry::DEFLATED, 400)
|
||||
entry = ::Zip::Entry.new(
|
||||
'file.zip', 'entry_name', comment: 'my little comment', size: 400,
|
||||
extra: 'thisIsSomeExtraInformation', compressed_size: 100, crc: 987_654
|
||||
)
|
||||
|
||||
write_to_file(LEH_FILE, CEH_FILE, entry)
|
||||
local_entry, central_entry = read_from_file(LEH_FILE, CEH_FILE)
|
||||
assert(
|
||||
|
@ -68,9 +70,10 @@ class ZipLocalEntryTest < MiniTest::Test
|
|||
|
||||
def test_write_entry_with_zip64
|
||||
::Zip.write_zip64_support = true
|
||||
entry = ::Zip::Entry.new('file.zip', 'entry_name', 'my little comment',
|
||||
'thisIsSomeExtraInformation', 100, 987_654,
|
||||
::Zip::Entry::DEFLATED, 400)
|
||||
entry = ::Zip::Entry.new(
|
||||
'file.zip', 'entry_name', comment: 'my little comment', size: 400,
|
||||
extra: 'thisIsSomeExtraInformation', compressed_size: 100, crc: 987_654
|
||||
)
|
||||
|
||||
write_to_file(LEH_FILE, CEH_FILE, entry)
|
||||
local_entry, central_entry = read_from_file(LEH_FILE, CEH_FILE)
|
||||
|
@ -92,11 +95,12 @@ class ZipLocalEntryTest < MiniTest::Test
|
|||
|
||||
def test_write_64entry
|
||||
::Zip.write_zip64_support = true
|
||||
entry = ::Zip::Entry.new('bigfile.zip', 'entry_name', 'my little equine',
|
||||
'malformed extra field because why not',
|
||||
0x7766554433221100, 0xDEADBEEF,
|
||||
::Zip::Entry::DEFLATED, ::Zip.default_compression,
|
||||
0x9988776655443322)
|
||||
entry = ::Zip::Entry.new(
|
||||
'bigfile.zip', 'entry_name', comment: 'my little equine',
|
||||
extra: 'malformed extra field because why not', size: 0x9988776655443322,
|
||||
compressed_size: 0x7766554433221100, crc: 0xDEADBEEF
|
||||
)
|
||||
|
||||
write_to_file(LEH_FILE, CEH_FILE, entry)
|
||||
local_entry, central_entry = read_from_file(LEH_FILE, CEH_FILE)
|
||||
compare_local_entry_headers(entry, local_entry)
|
||||
|
|
|
@ -92,7 +92,9 @@ class ZipOutputStreamTest < MiniTest::Test
|
|||
def test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps
|
||||
file = ::File.open('test/data/file2.txt', 'rb')
|
||||
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
|
||||
zip_entry = ::Zip::Entry.new(zos, file.path, '', '', 0, 0, ::Zip::Entry::DEFLATED, ::Zip.default_compression, 0, ::Zip::DOSTime.at(file.mtime))
|
||||
zip_entry = ::Zip::Entry.new(
|
||||
zos, file.path, time: ::Zip::DOSTime.at(file.mtime)
|
||||
)
|
||||
zos.put_next_entry(zip_entry)
|
||||
zos << file.read
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue