rubyzip 2.3.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +422 -0
  3. data/LICENSE.md +24 -0
  4. data/README.md +138 -41
  5. data/Rakefile +11 -7
  6. data/lib/zip/central_directory.rb +169 -123
  7. data/lib/zip/compressor.rb +3 -1
  8. data/lib/zip/constants.rb +29 -21
  9. data/lib/zip/crypto/decrypted_io.rb +4 -2
  10. data/lib/zip/crypto/encryption.rb +4 -2
  11. data/lib/zip/crypto/null_encryption.rb +6 -4
  12. data/lib/zip/crypto/traditional_encryption.rb +8 -6
  13. data/lib/zip/decompressor.rb +4 -3
  14. data/lib/zip/deflater.rb +10 -8
  15. data/lib/zip/dirtyable.rb +32 -0
  16. data/lib/zip/dos_time.rb +51 -5
  17. data/lib/zip/entry.rb +363 -222
  18. data/lib/zip/entry_set.rb +11 -9
  19. data/lib/zip/errors.rb +136 -16
  20. data/lib/zip/extra_field/generic.rb +6 -13
  21. data/lib/zip/extra_field/ntfs.rb +6 -4
  22. data/lib/zip/extra_field/old_unix.rb +3 -1
  23. data/lib/zip/extra_field/universal_time.rb +3 -1
  24. data/lib/zip/extra_field/unix.rb +5 -3
  25. data/lib/zip/extra_field/unknown.rb +33 -0
  26. data/lib/zip/extra_field/zip64.rb +12 -5
  27. data/lib/zip/extra_field.rb +16 -22
  28. data/lib/zip/file.rb +177 -223
  29. data/lib/zip/file_split.rb +91 -0
  30. data/lib/zip/filesystem/dir.rb +86 -0
  31. data/lib/zip/filesystem/directory_iterator.rb +48 -0
  32. data/lib/zip/filesystem/file.rb +262 -0
  33. data/lib/zip/filesystem/file_stat.rb +110 -0
  34. data/lib/zip/filesystem/zip_file_name_mapper.rb +81 -0
  35. data/lib/zip/filesystem.rb +27 -596
  36. data/lib/zip/inflater.rb +6 -4
  37. data/lib/zip/input_stream.rb +50 -37
  38. data/lib/zip/ioextras/abstract_input_stream.rb +15 -10
  39. data/lib/zip/ioextras/abstract_output_stream.rb +5 -3
  40. data/lib/zip/ioextras.rb +7 -7
  41. data/lib/zip/null_compressor.rb +3 -1
  42. data/lib/zip/null_decompressor.rb +3 -1
  43. data/lib/zip/null_input_stream.rb +3 -1
  44. data/lib/zip/output_stream.rb +53 -47
  45. data/lib/zip/pass_thru_compressor.rb +3 -1
  46. data/lib/zip/pass_thru_decompressor.rb +4 -2
  47. data/lib/zip/streamable_directory.rb +3 -1
  48. data/lib/zip/streamable_stream.rb +3 -0
  49. data/lib/zip/version.rb +3 -1
  50. data/lib/zip.rb +17 -23
  51. data/rubyzip.gemspec +39 -0
  52. data/samples/example.rb +8 -3
  53. data/samples/example_filesystem.rb +3 -2
  54. data/samples/example_recursive.rb +3 -1
  55. data/samples/gtk_ruby_zip.rb +4 -2
  56. data/samples/qtzip.rb +6 -5
  57. data/samples/write_simple.rb +2 -1
  58. data/samples/zipfind.rb +1 -0
  59. metadata +83 -33
  60. data/TODO +0 -15
  61. data/lib/zip/extra_field/zip64_placeholder.rb +0 -15
data/lib/zip/dos_time.rb CHANGED
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+
1
5
  module Zip
2
- class DOSTime < Time #:nodoc:all
6
+ class DOSTime < Time # :nodoc:all
3
7
  # MS-DOS File Date and Time format as used in Interrupt 21H Function 57H:
4
8
 
5
9
  # Register CX, the Time:
@@ -12,6 +16,14 @@ module Zip
12
16
  # bits 5-8 month (1-12)
13
17
  # bits 9-15 year (four digit year minus 1980)
14
18
 
19
+ attr_writer :absolute_time # :nodoc:
20
+
21
+ def absolute_time?
22
+ # If absolute time is not set, we can assume it is an absolute time
23
+ # because times do have timezone information by default.
24
+ @absolute_time.nil? ? true : @absolute_time
25
+ end
26
+
15
27
  def to_binary_dos_time
16
28
  (sec / 2) +
17
29
  (min << 5) +
@@ -24,9 +36,16 @@ module Zip
24
36
  ((year - 1980) << 9)
25
37
  end
26
38
 
27
- # Dos time is only stored with two seconds accuracy
28
39
  def dos_equals(other)
29
- to_i / 2 == other.to_i / 2
40
+ warn 'Zip::DOSTime#dos_equals is deprecated. Use `==` instead.'
41
+ self == other
42
+ end
43
+
44
+ # Dos time is only stored with two seconds accuracy.
45
+ def <=>(other)
46
+ return unless other.kind_of?(Time)
47
+
48
+ (to_i / 2) <=> (other.to_i / 2)
30
49
  end
31
50
 
32
51
  # Create a DOSTime instance from a vanilla Time instance.
@@ -41,9 +60,36 @@ module Zip
41
60
  day = (0b11111 & bin_dos_date)
42
61
  month = (0b111100000 & bin_dos_date) >> 5
43
62
  year = ((0b1111111000000000 & bin_dos_date) >> 9) + 1980
44
- begin
45
- local(year, month, day, hour, minute, second)
63
+
64
+ time = local(year, month, day, hour, minute, second)
65
+ time.absolute_time = false
66
+ time
67
+ end
68
+
69
+ if defined? JRUBY_VERSION && Gem::Version.new(JRUBY_VERSION) < '9.2.18.0'
70
+ module JRubyCMP # :nodoc:
71
+ def ==(other)
72
+ (self <=> other).zero?
73
+ end
74
+
75
+ def <(other)
76
+ (self <=> other).negative?
77
+ end
78
+
79
+ def <=(other)
80
+ (self <=> other) <= 0
81
+ end
82
+
83
+ def >(other)
84
+ (self <=> other).positive?
85
+ end
86
+
87
+ def >=(other)
88
+ (self <=> other) >= 0
89
+ end
46
90
  end
91
+
92
+ include JRubyCMP
47
93
  end
48
94
  end
49
95
  end