rubyzip 1.1.7 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +69 -32
- data/Rakefile +3 -4
- data/lib/zip.rb +3 -5
- data/lib/zip/central_directory.rb +7 -7
- data/lib/zip/compressor.rb +0 -0
- data/lib/zip/constants.rb +2 -2
- data/lib/zip/crypto/null_encryption.rb +3 -3
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +2 -2
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +4 -5
- data/lib/zip/entry.rb +68 -80
- data/lib/zip/entry_set.rb +11 -11
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +6 -6
- data/lib/zip/extra_field/generic.rb +7 -7
- data/lib/zip/extra_field/ntfs.rb +14 -16
- data/lib/zip/extra_field/old_unix.rb +9 -10
- data/lib/zip/extra_field/universal_time.rb +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +12 -11
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -1
- data/lib/zip/file.rb +45 -49
- data/lib/zip/filesystem.rb +132 -135
- data/lib/zip/inflater.rb +3 -3
- data/lib/zip/input_stream.rb +13 -7
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +0 -2
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -3
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +8 -9
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +2 -3
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +2 -2
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +33 -24
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +17 -26
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +24 -32
- data/test/basic_zip_file_test.rb +11 -15
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +31 -35
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +2 -2
- data/test/crypto/traditional_encryption_test.rb +5 -5
- data/test/data/notzippedruby.rb +1 -1
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/deflater_test.rb +10 -12
- data/test/encryption_test.rb +2 -2
- data/test/entry_set_test.rb +38 -24
- data/test/entry_test.rb +76 -78
- data/test/errors_test.rb +0 -2
- data/test/extra_field_test.rb +19 -21
- data/test/file_extract_directory_test.rb +12 -14
- data/test/file_extract_test.rb +33 -40
- data/test/file_permissions_test.rb +69 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +174 -170
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +80 -90
- data/test/filesystem/file_mutating_test.rb +51 -63
- data/test/filesystem/file_nonmutating_test.rb +222 -228
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +43 -55
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +42 -30
- data/test/ioextras/abstract_input_stream_test.rb +21 -22
- data/test/ioextras/abstract_output_stream_test.rb +32 -32
- data/test/local_entry_test.rb +35 -37
- data/test/output_stream_test.rb +20 -21
- data/test/pass_thru_compressor_test.rb +5 -6
- data/test/pass_thru_decompressor_test.rb +0 -1
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +37 -44
- data/test/unicode_file_names_and_comments_test.rb +5 -7
- data/test/zip64_full_test.rb +9 -11
- data/test/zip64_support_test.rb +0 -1
- metadata +14 -32
data/lib/zip/entry.rb
CHANGED
@@ -39,15 +39,14 @@ module Zip
|
|
39
39
|
@unix_uid = nil
|
40
40
|
@unix_gid = nil
|
41
41
|
@unix_perms = nil
|
42
|
-
|
43
|
-
|
42
|
+
# @posix_acl = nil
|
43
|
+
# @ntfs_acl = nil
|
44
44
|
@dirty = false
|
45
45
|
end
|
46
46
|
|
47
47
|
def check_name(name)
|
48
|
-
|
49
|
-
|
50
|
-
end
|
48
|
+
return unless name.start_with?('/')
|
49
|
+
raise ::Zip::EntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
|
51
50
|
end
|
52
51
|
|
53
52
|
def initialize(*args)
|
@@ -68,7 +67,7 @@ module Zip
|
|
68
67
|
@time = args[8] || ::Zip::DOSTime.now
|
69
68
|
|
70
69
|
@ftype = name_is_directory? ? :directory : :file
|
71
|
-
@extra = ::Zip::ExtraField.new(@extra.to_s) unless ::Zip::ExtraField
|
70
|
+
@extra = ::Zip::ExtraField.new(@extra.to_s) unless @extra.is_a?(::Zip::ExtraField)
|
72
71
|
end
|
73
72
|
|
74
73
|
def time
|
@@ -83,7 +82,7 @@ module Zip
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
86
|
-
alias
|
85
|
+
alias mtime time
|
87
86
|
|
88
87
|
def time=(value)
|
89
88
|
unless @extra.member?('UniversalTime') || @extra.member?('NTFS')
|
@@ -94,7 +93,7 @@ module Zip
|
|
94
93
|
end
|
95
94
|
|
96
95
|
def file_type_is?(type)
|
97
|
-
raise InternalError, "current filetype is unknown: #{
|
96
|
+
raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype
|
98
97
|
@ftype == type
|
99
98
|
end
|
100
99
|
|
@@ -143,7 +142,7 @@ module Zip
|
|
143
142
|
end
|
144
143
|
|
145
144
|
def next_header_offset #:nodoc:all
|
146
|
-
local_entry_offset +
|
145
|
+
local_entry_offset + compressed_size + data_descriptor_size
|
147
146
|
end
|
148
147
|
|
149
148
|
# Extracts entry to file dest_path (defaults to @name).
|
@@ -151,9 +150,9 @@ module Zip
|
|
151
150
|
block ||= proc { ::Zip.on_exists_proc }
|
152
151
|
|
153
152
|
if directory? || file? || symlink?
|
154
|
-
|
153
|
+
__send__("create_#{@ftype}", dest_path, &block)
|
155
154
|
else
|
156
|
-
raise
|
155
|
+
raise "unknown file type #{inspect}"
|
157
156
|
end
|
158
157
|
|
159
158
|
self
|
@@ -163,8 +162,6 @@ module Zip
|
|
163
162
|
@name
|
164
163
|
end
|
165
164
|
|
166
|
-
protected
|
167
|
-
|
168
165
|
class << self
|
169
166
|
def read_zip_short(io) # :nodoc:
|
170
167
|
io.read(2).unpack('v')[0]
|
@@ -179,11 +176,11 @@ module Zip
|
|
179
176
|
end
|
180
177
|
|
181
178
|
def read_c_dir_entry(io) #:nodoc:all
|
182
|
-
path = if io.
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
179
|
+
path = if io.respond_to?(:path)
|
180
|
+
io.path
|
181
|
+
else
|
182
|
+
io
|
183
|
+
end
|
187
184
|
entry = new(path)
|
188
185
|
entry.read_c_dir_entry(io)
|
189
186
|
entry
|
@@ -192,13 +189,12 @@ module Zip
|
|
192
189
|
end
|
193
190
|
|
194
191
|
def read_local_entry(io)
|
195
|
-
entry =
|
192
|
+
entry = new(io)
|
196
193
|
entry.read_local_entry(io)
|
197
194
|
entry
|
198
195
|
rescue Error
|
199
196
|
nil
|
200
197
|
end
|
201
|
-
|
202
198
|
end
|
203
199
|
|
204
200
|
public
|
@@ -221,10 +217,10 @@ module Zip
|
|
221
217
|
def read_local_entry(io) #:nodoc:all
|
222
218
|
@local_header_offset = io.tell
|
223
219
|
|
224
|
-
static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH)
|
220
|
+
static_sized_fields_buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || ''
|
225
221
|
|
226
222
|
unless static_sized_fields_buf.bytesize == ::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH
|
227
|
-
raise Error,
|
223
|
+
raise Error, 'Premature end of file. Not enough data for zip entry local header'
|
228
224
|
end
|
229
225
|
|
230
226
|
unpack_local_entry(static_sized_fields_buf)
|
@@ -240,10 +236,10 @@ module Zip
|
|
240
236
|
@name.gsub!('\\', '/')
|
241
237
|
|
242
238
|
if extra && extra.bytesize != @extra_length
|
243
|
-
raise ::Zip::Error,
|
239
|
+
raise ::Zip::Error, 'Truncated local zip entry header'
|
244
240
|
else
|
245
|
-
if ::Zip::ExtraField
|
246
|
-
@extra.merge(extra)
|
241
|
+
if @extra.is_a?(::Zip::ExtraField)
|
242
|
+
@extra.merge(extra) if extra
|
247
243
|
else
|
248
244
|
@extra = ::Zip::ExtraField.new(extra)
|
249
245
|
end
|
@@ -315,8 +311,8 @@ module Zip
|
|
315
311
|
when ::Zip::FILE_TYPE_SYMLINK
|
316
312
|
:symlink
|
317
313
|
else
|
318
|
-
#best case guess for whether it is a file or not
|
319
|
-
#Otherwise this would be set to unknown and that entry would never be able to extracted
|
314
|
+
# best case guess for whether it is a file or not
|
315
|
+
# Otherwise this would be set to unknown and that entry would never be able to extracted
|
320
316
|
if name_is_directory?
|
321
317
|
:directory
|
322
318
|
else
|
@@ -333,21 +329,18 @@ module Zip
|
|
333
329
|
end
|
334
330
|
|
335
331
|
def check_c_dir_entry_static_header_length(buf)
|
336
|
-
|
337
|
-
|
338
|
-
end
|
332
|
+
return if buf.bytesize == ::Zip::CDIR_ENTRY_STATIC_HEADER_LENGTH
|
333
|
+
raise Error, 'Premature end of file. Not enough data for zip cdir entry header'
|
339
334
|
end
|
340
335
|
|
341
336
|
def check_c_dir_entry_signature
|
342
|
-
|
343
|
-
|
344
|
-
end
|
337
|
+
return if header_signature == ::Zip::CENTRAL_DIRECTORY_ENTRY_SIGNATURE
|
338
|
+
raise Error, "Zip local header magic not found at location '#{local_header_offset}'"
|
345
339
|
end
|
346
340
|
|
347
341
|
def check_c_dir_entry_comment_size
|
348
|
-
|
349
|
-
|
350
|
-
end
|
342
|
+
return if @comment && @comment.bytesize == @comment_length
|
343
|
+
raise ::Zip::Error, 'Truncated cdir zip entry header'
|
351
344
|
end
|
352
345
|
|
353
346
|
def read_c_dir_extra_field(io)
|
@@ -374,19 +367,18 @@ module Zip
|
|
374
367
|
|
375
368
|
def file_stat(path) # :nodoc:
|
376
369
|
if @follow_symlinks
|
377
|
-
::File
|
370
|
+
::File.stat(path)
|
378
371
|
else
|
379
|
-
::File
|
372
|
+
::File.lstat(path)
|
380
373
|
end
|
381
374
|
end
|
382
375
|
|
383
376
|
def get_extra_attributes_from_path(path) # :nodoc:
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
end
|
377
|
+
return if Zip::RUNNING_ON_WINDOWS
|
378
|
+
stat = file_stat(path)
|
379
|
+
@unix_uid = stat.uid
|
380
|
+
@unix_gid = stat.gid
|
381
|
+
@unix_perms = stat.mode & 07777
|
390
382
|
end
|
391
383
|
|
392
384
|
def set_unix_permissions_on_path(dest_path)
|
@@ -400,7 +392,7 @@ module Zip
|
|
400
392
|
end
|
401
393
|
|
402
394
|
def set_extra_attributes_on_path(dest_path) # :nodoc:
|
403
|
-
return unless
|
395
|
+
return unless file? || directory?
|
404
396
|
|
405
397
|
case @fstype
|
406
398
|
when ::Zip::FSTYPE_UNIX
|
@@ -467,13 +459,13 @@ module Zip
|
|
467
459
|
return false unless other.class == self.class
|
468
460
|
# Compares contents of local entry and exposed fields
|
469
461
|
keys_equal = %w(compression_method crc compressed_size size name extra filepath).all? do |k|
|
470
|
-
other.__send__(k.to_sym) ==
|
462
|
+
other.__send__(k.to_sym) == __send__(k.to_sym)
|
471
463
|
end
|
472
|
-
keys_equal &&
|
464
|
+
keys_equal && time.dos_equals(other.time)
|
473
465
|
end
|
474
466
|
|
475
|
-
def <=>
|
476
|
-
|
467
|
+
def <=>(other)
|
468
|
+
to_s <=> other.to_s
|
477
469
|
end
|
478
470
|
|
479
471
|
# Returns an IO like object for the given ZipEntry.
|
@@ -496,6 +488,7 @@ module Zip
|
|
496
488
|
end
|
497
489
|
else
|
498
490
|
zis = ::Zip::InputStream.new(@zipfile, local_header_offset)
|
491
|
+
zis.instance_variable_set(:@internal, true)
|
499
492
|
zis.get_next_entry
|
500
493
|
if block_given?
|
501
494
|
begin
|
@@ -515,8 +508,8 @@ module Zip
|
|
515
508
|
when 'file'
|
516
509
|
if name_is_directory?
|
517
510
|
raise ArgumentError,
|
518
|
-
"entry name '#{newEntry}' indicates directory entry, but "
|
519
|
-
|
511
|
+
"entry name '#{newEntry}' indicates directory entry, but " \
|
512
|
+
"'#{src_path}' is not a directory"
|
520
513
|
end
|
521
514
|
:file
|
522
515
|
when 'directory'
|
@@ -525,12 +518,12 @@ module Zip
|
|
525
518
|
when 'link'
|
526
519
|
if name_is_directory?
|
527
520
|
raise ArgumentError,
|
528
|
-
"entry name '#{newEntry}' indicates directory entry, but "
|
529
|
-
|
521
|
+
"entry name '#{newEntry}' indicates directory entry, but " \
|
522
|
+
"'#{src_path}' is not a directory"
|
530
523
|
end
|
531
524
|
:symlink
|
532
525
|
else
|
533
|
-
raise
|
526
|
+
raise "unknown file type: #{src_path.inspect} #{stat.inspect}"
|
534
527
|
end
|
535
528
|
|
536
529
|
@filepath = src_path
|
@@ -541,7 +534,7 @@ module Zip
|
|
541
534
|
if @ftype == :directory
|
542
535
|
zip_output_stream.put_next_entry(self, nil, nil, ::Zip::Entry::STORED)
|
543
536
|
elsif @filepath
|
544
|
-
zip_output_stream.put_next_entry(self, nil, nil,
|
537
|
+
zip_output_stream.put_next_entry(self, nil, nil, compression_method || ::Zip::Entry::DEFLATED)
|
545
538
|
get_input_stream { |is| ::Zip::IOExtras.copy_stream(zip_output_stream, is) }
|
546
539
|
else
|
547
540
|
zip_output_stream.copy_raw_entry(self)
|
@@ -551,14 +544,14 @@ module Zip
|
|
551
544
|
def parent_as_string
|
552
545
|
entry_name = name.chomp('/')
|
553
546
|
slash_index = entry_name.rindex('/')
|
554
|
-
slash_index ? entry_name.slice(0, slash_index+1) : nil
|
547
|
+
slash_index ? entry_name.slice(0, slash_index + 1) : nil
|
555
548
|
end
|
556
549
|
|
557
550
|
def get_raw_input_stream(&block)
|
558
|
-
if @zipfile.
|
551
|
+
if @zipfile.respond_to?(:seek) && @zipfile.respond_to?(:read)
|
559
552
|
yield @zipfile
|
560
553
|
else
|
561
|
-
::File.open(@zipfile,
|
554
|
+
::File.open(@zipfile, 'rb', &block)
|
562
555
|
end
|
563
556
|
end
|
564
557
|
|
@@ -571,20 +564,20 @@ module Zip
|
|
571
564
|
def set_time(binary_dos_date, binary_dos_time)
|
572
565
|
@time = ::Zip::DOSTime.parse_binary_dos_format(binary_dos_date, binary_dos_time)
|
573
566
|
rescue ArgumentError
|
574
|
-
|
567
|
+
warn 'Invalid date/time in zip entry' if ::Zip.warn_invalid_date
|
575
568
|
end
|
576
569
|
|
577
|
-
def create_file(dest_path,
|
570
|
+
def create_file(dest_path, _continue_on_exists_proc = proc { Zip.continue_on_exists_proc })
|
578
571
|
if ::File.exist?(dest_path) && !yield(self, dest_path)
|
579
572
|
raise ::Zip::DestinationFileExistsError,
|
580
573
|
"Destination '#{dest_path}' already exists"
|
581
574
|
end
|
582
|
-
::File.open(dest_path,
|
575
|
+
::File.open(dest_path, 'wb') do |os|
|
583
576
|
get_input_stream do |is|
|
584
577
|
set_extra_attributes_on_path(dest_path)
|
585
578
|
|
586
579
|
buf = ''
|
587
|
-
while buf = is.sysread(::Zip::Decompressor::CHUNK_SIZE, buf)
|
580
|
+
while (buf = is.sysread(::Zip::Decompressor::CHUNK_SIZE, buf))
|
588
581
|
os << buf
|
589
582
|
end
|
590
583
|
end
|
@@ -595,11 +588,11 @@ module Zip
|
|
595
588
|
return if ::File.directory?(dest_path)
|
596
589
|
if ::File.exist?(dest_path)
|
597
590
|
if block_given? && yield(self, dest_path)
|
598
|
-
::FileUtils
|
591
|
+
::FileUtils.rm_f dest_path
|
599
592
|
else
|
600
593
|
raise ::Zip::DestinationFileExistsError,
|
601
|
-
"Cannot create directory '#{dest_path}'. "
|
602
|
-
|
594
|
+
"Cannot create directory '#{dest_path}'. " \
|
595
|
+
'A file already exists with that name'
|
603
596
|
end
|
604
597
|
end
|
605
598
|
::FileUtils.mkdir_p(dest_path)
|
@@ -623,13 +616,13 @@ module Zip
|
|
623
616
|
return
|
624
617
|
else
|
625
618
|
raise ::Zip::DestinationFileExistsError,
|
626
|
-
"Cannot create symlink '#{dest_path}'. "
|
627
|
-
|
619
|
+
"Cannot create symlink '#{dest_path}'. " \
|
620
|
+
'A symlink already exists with that name'
|
628
621
|
end
|
629
622
|
else
|
630
623
|
raise ::Zip::DestinationFileExistsError,
|
631
|
-
"Cannot create symlink '#{dest_path}'. "
|
632
|
-
|
624
|
+
"Cannot create symlink '#{dest_path}'. " \
|
625
|
+
'A file already exists with that name'
|
633
626
|
end
|
634
627
|
end
|
635
628
|
|
@@ -639,12 +632,11 @@ module Zip
|
|
639
632
|
# apply missing data from the zip64 extra information field, if present
|
640
633
|
# (required when file sizes exceed 2**32, but can be used for all files)
|
641
634
|
def parse_zip64_extra(for_local_header) #:nodoc:all
|
642
|
-
if
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
end
|
635
|
+
return if @extra['Zip64'].nil?
|
636
|
+
if for_local_header
|
637
|
+
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
|
638
|
+
else
|
639
|
+
@size, @compressed_size, @local_header_offset = @extra['Zip64'].parse(@size, @compressed_size, @local_header_offset)
|
648
640
|
end
|
649
641
|
end
|
650
642
|
|
@@ -656,10 +648,7 @@ module Zip
|
|
656
648
|
def prep_zip64_extra(for_local_header) #:nodoc:all
|
657
649
|
return unless ::Zip.write_zip64_support
|
658
650
|
need_zip64 = @size >= 0xFFFFFFFF || @compressed_size >= 0xFFFFFFFF
|
659
|
-
unless for_local_header
|
660
|
-
need_zip64 ||= @local_header_offset >= 0xFFFFFFFF
|
661
|
-
end
|
662
|
-
|
651
|
+
need_zip64 ||= @local_header_offset >= 0xFFFFFFFF unless for_local_header
|
663
652
|
if need_zip64
|
664
653
|
@version_needed_to_extract = VERSION_NEEDED_TO_EXTRACT_ZIP64
|
665
654
|
@extra.delete('Zip64Placeholder')
|
@@ -687,7 +676,6 @@ module Zip
|
|
687
676
|
end
|
688
677
|
end
|
689
678
|
end
|
690
|
-
|
691
679
|
end
|
692
680
|
end
|
693
681
|
|
data/lib/zip/entry_set.rb
CHANGED
@@ -18,23 +18,19 @@ module Zip
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def <<(entry)
|
21
|
-
@entry_set[to_key(entry)] = entry
|
21
|
+
@entry_set[to_key(entry)] = entry if entry
|
22
22
|
end
|
23
23
|
|
24
|
-
alias
|
24
|
+
alias push <<
|
25
25
|
|
26
26
|
def size
|
27
27
|
@entry_set.size
|
28
28
|
end
|
29
29
|
|
30
|
-
alias
|
30
|
+
alias length size
|
31
31
|
|
32
32
|
def delete(entry)
|
33
|
-
if @entry_set.delete(to_key(entry))
|
34
|
-
entry
|
35
|
-
else
|
36
|
-
nil
|
37
|
-
end
|
33
|
+
entry if @entry_set.delete(to_key(entry))
|
38
34
|
end
|
39
35
|
|
40
36
|
def each(&block)
|
@@ -49,7 +45,7 @@ module Zip
|
|
49
45
|
|
50
46
|
# deep clone
|
51
47
|
def dup
|
52
|
-
EntrySet.new(@entry_set.map
|
48
|
+
EntrySet.new(@entry_set.values.map(&:dup))
|
53
49
|
end
|
54
50
|
|
55
51
|
def ==(other)
|
@@ -61,7 +57,7 @@ module Zip
|
|
61
57
|
@entry_set[to_key(entry.parent_as_string)]
|
62
58
|
end
|
63
59
|
|
64
|
-
def glob(pattern, flags = ::File::FNM_PATHNAME
|
60
|
+
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH)
|
65
61
|
entries.map do |entry|
|
66
62
|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
|
67
63
|
yield(entry) if block_given?
|
@@ -70,13 +66,17 @@ module Zip
|
|
70
66
|
end
|
71
67
|
|
72
68
|
protected
|
69
|
+
|
73
70
|
def sorted_entries
|
74
71
|
::Zip.sort_entries ? Hash[@entry_set.sort] : @entry_set
|
75
72
|
end
|
76
73
|
|
77
74
|
private
|
75
|
+
|
78
76
|
def to_key(entry)
|
79
|
-
entry.to_s.chomp('/')
|
77
|
+
k = entry.to_s.chomp('/')
|
78
|
+
k.downcase! if ::Zip.case_insensitive_match
|
79
|
+
k
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
data/lib/zip/errors.rb
CHANGED
data/lib/zip/extra_field.rb
CHANGED
@@ -3,7 +3,7 @@ module Zip
|
|
3
3
|
ID_MAP = {}
|
4
4
|
|
5
5
|
def initialize(binstr = nil)
|
6
|
-
binstr
|
6
|
+
merge(binstr) if binstr
|
7
7
|
end
|
8
8
|
|
9
9
|
def extra_field_type_exist(binstr, id, len, i)
|
@@ -51,7 +51,7 @@ module Zip
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def create(name)
|
54
|
-
unless field_class = ID_MAP.values.find { |k| k.name == name }
|
54
|
+
unless (field_class = ID_MAP.values.find { |k| k.name == name })
|
55
55
|
raise Error, "Unknown extra field '#{name}'"
|
56
56
|
end
|
57
57
|
self[name] = field_class.new
|
@@ -61,7 +61,7 @@ module Zip
|
|
61
61
|
# does not prevent known fields from being read back in
|
62
62
|
def ordered_values
|
63
63
|
result = []
|
64
|
-
|
64
|
+
each { |k, v| k == 'Unknown' ? result.push(v) : result.unshift(v) }
|
65
65
|
result
|
66
66
|
end
|
67
67
|
|
@@ -69,7 +69,7 @@ module Zip
|
|
69
69
|
ordered_values.map! { |v| v.to_local_bin.force_encoding('BINARY') }.join
|
70
70
|
end
|
71
71
|
|
72
|
-
alias
|
72
|
+
alias to_s to_local_bin
|
73
73
|
|
74
74
|
def to_c_dir_bin
|
75
75
|
ordered_values.map! { |v| v.to_c_dir_bin.force_encoding('BINARY') }.join
|
@@ -83,8 +83,8 @@ module Zip
|
|
83
83
|
to_local_bin.bytesize
|
84
84
|
end
|
85
85
|
|
86
|
-
alias
|
87
|
-
alias
|
86
|
+
alias length local_size
|
87
|
+
alias size local_size
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|