archive-zip 0.11.0 → 0.13.0.pre1

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 (133) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/NEWS.md +12 -0
  4. data/README.md +2 -1
  5. data/lib/archive/support/ioextensions.rb +5 -7
  6. data/lib/archive/support/iowindow.rb +34 -87
  7. data/lib/archive/support/stringio.rb +27 -0
  8. data/lib/archive/support/zlib.rb +0 -435
  9. data/lib/archive/zip/codec/deflate/reader.rb +187 -0
  10. data/lib/archive/zip/codec/deflate/writer.rb +209 -0
  11. data/lib/archive/zip/codec/deflate.rb +92 -244
  12. data/lib/archive/zip/codec/null_encryption.rb +4 -184
  13. data/lib/archive/zip/codec/store/reader.rb +97 -0
  14. data/lib/archive/zip/codec/store/writer.rb +78 -0
  15. data/lib/archive/zip/codec/store.rb +6 -231
  16. data/lib/archive/zip/codec/traditional_encryption/base.rb +85 -0
  17. data/lib/archive/zip/codec/traditional_encryption/reader.rb +65 -0
  18. data/lib/archive/zip/codec/traditional_encryption/writer.rb +71 -0
  19. data/lib/archive/zip/codec/traditional_encryption.rb +6 -360
  20. data/lib/archive/zip/codec.rb +2 -2
  21. data/lib/archive/zip/dos_time.rb +103 -0
  22. data/lib/archive/zip/entry.rb +86 -70
  23. data/lib/archive/zip.rb +2 -5
  24. metadata +37 -227
  25. data/.yardopts +0 -1
  26. data/Rakefile +0 -247
  27. data/lib/archive/support/binary_stringio.rb +0 -30
  28. data/lib/archive/support/integer.rb +0 -13
  29. data/lib/archive/support/io-like.rb +0 -14
  30. data/lib/archive/support/time.rb +0 -119
  31. data/lib/archive/zip/version.rb +0 -6
  32. data/spec/archive/dos_time_spec.rb +0 -113
  33. data/spec/archive/zip/archive_spec.rb +0 -54
  34. data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +0 -44
  35. data/spec/archive/zip/codec/deflate/compress/close_spec.rb +0 -45
  36. data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +0 -23
  37. data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +0 -74
  38. data/spec/archive/zip/codec/deflate/compress/new_spec.rb +0 -39
  39. data/spec/archive/zip/codec/deflate/compress/open_spec.rb +0 -48
  40. data/spec/archive/zip/codec/deflate/compress/write_spec.rb +0 -111
  41. data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +0 -20
  42. data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +0 -34
  43. data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +0 -20
  44. data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +0 -74
  45. data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +0 -16
  46. data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +0 -29
  47. data/spec/archive/zip/codec/deflate/fixtures/classes.rb +0 -25
  48. data/spec/archive/zip/codec/deflate/fixtures/compressed_file.bin +0 -1
  49. data/spec/archive/zip/codec/deflate/fixtures/compressed_file_nocomp.bin +0 -0
  50. data/spec/archive/zip/codec/deflate/fixtures/raw_file.txt +0 -10
  51. data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +0 -34
  52. data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +0 -16
  53. data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +0 -29
  54. data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +0 -26
  55. data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +0 -27
  56. data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +0 -59
  57. data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +0 -23
  58. data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +0 -34
  59. data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +0 -16
  60. data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +0 -31
  61. data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +0 -28
  62. data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +0 -52
  63. data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +0 -31
  64. data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +0 -31
  65. data/spec/archive/zip/codec/null_encryption/fixtures/classes.rb +0 -12
  66. data/spec/archive/zip/codec/null_encryption/fixtures/raw_file.txt +0 -10
  67. data/spec/archive/zip/codec/store/compress/close_spec.rb +0 -34
  68. data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +0 -77
  69. data/spec/archive/zip/codec/store/compress/new_spec.rb +0 -16
  70. data/spec/archive/zip/codec/store/compress/open_spec.rb +0 -29
  71. data/spec/archive/zip/codec/store/compress/rewind_spec.rb +0 -28
  72. data/spec/archive/zip/codec/store/compress/seek_spec.rb +0 -52
  73. data/spec/archive/zip/codec/store/compress/tell_spec.rb +0 -31
  74. data/spec/archive/zip/codec/store/compress/write_spec.rb +0 -29
  75. data/spec/archive/zip/codec/store/decompress/close_spec.rb +0 -34
  76. data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +0 -75
  77. data/spec/archive/zip/codec/store/decompress/new_spec.rb +0 -16
  78. data/spec/archive/zip/codec/store/decompress/open_spec.rb +0 -29
  79. data/spec/archive/zip/codec/store/decompress/read_spec.rb +0 -26
  80. data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +0 -27
  81. data/spec/archive/zip/codec/store/decompress/seek_spec.rb +0 -59
  82. data/spec/archive/zip/codec/store/decompress/tell_spec.rb +0 -23
  83. data/spec/archive/zip/codec/store/fixtures/classes.rb +0 -12
  84. data/spec/archive/zip/codec/store/fixtures/raw_file.txt +0 -10
  85. data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +0 -53
  86. data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +0 -20
  87. data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +0 -43
  88. data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +0 -127
  89. data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +0 -36
  90. data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +0 -80
  91. data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +0 -27
  92. data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +0 -53
  93. data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +0 -20
  94. data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +0 -41
  95. data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +0 -39
  96. data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +0 -73
  97. data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +0 -40
  98. data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +0 -114
  99. data/spec/archive/zip/codec/traditional_encryption/fixtures/classes.rb +0 -27
  100. data/spec/archive/zip/codec/traditional_encryption/fixtures/encrypted_file.bin +0 -0
  101. data/spec/archive/zip/codec/traditional_encryption/fixtures/raw_file.txt +0 -10
  102. data/spec/binary_stringio/new_spec.rb +0 -40
  103. data/spec/binary_stringio/set_encoding_spec.rb +0 -17
  104. data/spec/ioextensions/read_exactly_spec.rb +0 -52
  105. data/spec/zlib/fixtures/classes.rb +0 -65
  106. data/spec/zlib/fixtures/compressed_file.bin +0 -1
  107. data/spec/zlib/fixtures/compressed_file_gzip.bin +0 -0
  108. data/spec/zlib/fixtures/compressed_file_huffman.bin +0 -2
  109. data/spec/zlib/fixtures/compressed_file_minmem.bin +0 -0
  110. data/spec/zlib/fixtures/compressed_file_minwin.bin +0 -1
  111. data/spec/zlib/fixtures/compressed_file_nocomp.bin +0 -0
  112. data/spec/zlib/fixtures/compressed_file_raw.bin +0 -1
  113. data/spec/zlib/fixtures/raw_file.txt +0 -10
  114. data/spec/zlib/zreader/checksum_spec.rb +0 -42
  115. data/spec/zlib/zreader/close_spec.rb +0 -16
  116. data/spec/zlib/zreader/compressed_size_spec.rb +0 -20
  117. data/spec/zlib/zreader/new_spec.rb +0 -43
  118. data/spec/zlib/zreader/open_spec.rb +0 -51
  119. data/spec/zlib/zreader/read_spec.rb +0 -58
  120. data/spec/zlib/zreader/rewind_spec.rb +0 -25
  121. data/spec/zlib/zreader/seek_spec.rb +0 -57
  122. data/spec/zlib/zreader/tell_spec.rb +0 -23
  123. data/spec/zlib/zreader/uncompressed_size_spec.rb +0 -20
  124. data/spec/zlib/zwriter/checksum_spec.rb +0 -43
  125. data/spec/zlib/zwriter/close_spec.rb +0 -16
  126. data/spec/zlib/zwriter/compressed_size_spec.rb +0 -21
  127. data/spec/zlib/zwriter/new_spec.rb +0 -66
  128. data/spec/zlib/zwriter/open_spec.rb +0 -70
  129. data/spec/zlib/zwriter/rewind_spec.rb +0 -28
  130. data/spec/zlib/zwriter/seek_spec.rb +0 -52
  131. data/spec/zlib/zwriter/tell_spec.rb +0 -31
  132. data/spec/zlib/zwriter/uncompressed_size_spec.rb +0 -21
  133. data/spec/zlib/zwriter/write_spec.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b3ed9fe304aaaccf2112d79acd33be3594225385
4
- data.tar.gz: c09cbfbc1500cc9788a1f495e5063dcfa3660ea1
2
+ SHA256:
3
+ metadata.gz: 1392110deef4d2f5d326613b369c129ba6c59802c8951d0f93c71f98f70e7b8c
4
+ data.tar.gz: 7d3d4fee38aa65051e96ec62364ee0642d0219488bb272e04c062e227735da75
5
5
  SHA512:
6
- metadata.gz: da51b451dacabbb6fbcdad58d9fc0851d474e70ba0047df1676f5ecb148e501d82341122ebe533ff67ab2341201ffc6225dc8c0da9350fc197379168605384b1
7
- data.tar.gz: 764188649dca68e41c8fd651fd1aba216e257d7856dcb7aa86c5f71d8d5105d185168c4b29c11034f4a1e0ee92b2dab4f1a5c54dcb8c4815eb32f66da7267993
6
+ metadata.gz: c46f9a08a470b353fd154e2d958c7ccd4454494a02f89d105b1cc567f6c66ca3ee284b49082e0875bbcbadd2da70ca7def0a0161efa1dfa0a2fba24029034712
7
+ data.tar.gz: c783d1001480fe8ef5756103101989e421855fd6f7435199bd29d338ce30745dda7ee2838b68a76201a9ddba04ee99f1de4515415ff087ab58d67b91d1dbfab8
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2018 Jeremy Bopp
3
+ Copyright (c) 2025 Jeremy Bopp
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/NEWS.md CHANGED
@@ -6,6 +6,18 @@ detailed information is available in the rest of the documentation.
6
6
  **NOTE:** Date stamps in the following entries are in YYYY/MM/DD format.
7
7
 
8
8
 
9
+ ## v0.13.0.pre1 (2025/05/25)
10
+
11
+ * Upgrade io-like dependency to 0.4.0.pre1
12
+ * Add more test coverage
13
+
14
+ ## v0.12.0 (2019/02/28)
15
+
16
+ ### Fixes
17
+
18
+ * Check for codec availability before attempting to initialize a codec instance
19
+ during extraction. (Kouhei Sutou)
20
+
9
21
  ## v0.11.0 (2018/01/28)
10
22
 
11
23
  ### Fixes
data/README.md CHANGED
@@ -183,6 +183,7 @@ Thanks to all contributors. Without your help this project would not exist.
183
183
  * Jeremy Bopp :: jeremy@bopp.net
184
184
  * Akira Matsuda :: ronnie@dio.jp
185
185
  * Tatsuya Sato :: tatsuya.b.sato@rakuten.com
186
+ * Kouhei Sutou :: kou@clear-code.com
186
187
 
187
188
  ## CONTRIBUTING
188
189
 
@@ -229,7 +230,7 @@ be more easily accepted if they are consistent with the rest of the code.
229
230
  ```
230
231
  (The MIT License)
231
232
 
232
- Copyright (c) 2018 Jeremy Bopp
233
+ Copyright (c) 2025 Jeremy Bopp
233
234
 
234
235
  Permission is hereby granted, free of charge, to any person obtaining
235
236
  a copy of this software and associated documentation files (the
@@ -4,13 +4,11 @@
4
4
  module IOExtensions
5
5
  # Reads and returns exactly _length_ bytes from _io_ using the read method on
6
6
  # _io_. If there is insufficient data available, an EOFError is raised.
7
- def self.read_exactly(io, length, buffer = '')
8
- buffer.slice!(0..-1) unless buffer.empty?
9
- while buffer.size < length do
10
- internal = io.read(length - buffer.size)
11
- raise EOFError, 'unexpected end of file' if internal.nil?
12
- buffer << internal
7
+ def self.read_exactly(io, length)
8
+ result = io.read(length)
9
+ if result.nil? || result.bytesize < length
10
+ raise EOFError, 'unexpected end of file'
13
11
  end
14
- buffer
12
+ result
15
13
  end
16
14
  end
@@ -1,115 +1,62 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'archive/support/io-like'
4
-
5
- # IOWindow represents an IO object which wraps another one allowing read and/or
6
- # write access to a subset of the data within the stream.
7
- #
8
- # <b>NOTE:</b> This object is NOT thread safe.
9
- class IOWindow
10
- include IO::Like
11
-
12
- # Creates a new instance of this class using _io_ as the data source
13
- # and where _window_position_ and _window_size_ define the location and size
14
- # of data window respectively.
3
+ require 'io/like_helpers/delegated_io'
4
+
5
+ # IOWindow represents an IO object which wraps another one allowing read access
6
+ # to a subset of the data within the stream.
7
+ class IOWindow < IO::LikeHelpers::DelegatedIO
8
+ # Creates a new instance of this class using _delegate_ as the data source and
9
+ # where _window_position_ and _window_size_ define the location and size of
10
+ # data window respectively.
15
11
  #
16
- # _io_ must be opened for reading and must be seekable. _window_position_
17
- # must be an integer greater than or equal to 0. _window_size_ must be an
18
- # integer greater than or equal to 0.
19
- def initialize(io, window_position, window_size)
20
- @io = io
21
- @unbuffered_pos = 0
22
- self.window_position = window_position
23
- self.window_size = window_size
24
- end
25
-
26
- # The file position at which this window begins.
27
- attr_reader :window_position
28
-
29
- # Set the file position at which this window begins.
12
+ # _delegate_ must be opened for reading and must be seekable.
30
13
  # _window_position_ must be an integer greater than or equal to 0.
31
- def window_position=(window_position)
32
- unless window_position.respond_to?(:to_int) then
33
- raise TypeError, "can't convert #{window_position.class} into Integer"
34
- end
35
- window_position = window_position.to_int
36
- if window_position < 0 then
37
- raise ArgumentError, 'non-positive window position given'
38
- end
39
-
40
- @window_position = window_position
41
- end
42
-
43
- # The size of the window.
44
- attr_reader :window_size
45
-
46
- # Set the size of the window.
47
14
  # _window_size_ must be an integer greater than or equal to 0.
48
- def window_size=(window_size)
49
- unless window_size.respond_to?(:to_int) then
50
- raise TypeError, "can't convert #{window_size.class} into Integer"
15
+ def initialize(delegate, window_position, window_size, autoclose: true)
16
+ super(delegate, autoclose: autoclose)
17
+
18
+ @window_position = Integer(window_position)
19
+ if @window_position < 0
20
+ raise ArgumentError, 'window_position must be at least 0'
51
21
  end
52
- window_size = window_size.to_int
53
- raise ArgumentError, 'non-positive window size given' if window_size < 0
22
+ @window_size = Integer(window_size)
23
+ raise ArgumentError, 'window_size must be at least 0' if @window_size < 0
54
24
 
55
- @window_size = window_size
25
+ @pos = 0
56
26
  end
57
27
 
58
- private
59
-
60
- def unbuffered_read(length)
61
- restore_self
62
-
28
+ def read(length, buffer: nil, buffer_offset: 0)
63
29
  # Error out if the end of the window is reached.
64
- raise EOFError, 'end of file reached' if @unbuffered_pos >= @window_size
30
+ raise EOFError, 'end of file reached' if @pos >= @window_size
65
31
 
66
32
  # Limit the read operation to the window.
67
- length = @window_size - @unbuffered_pos if @unbuffered_pos + length > @window_size
33
+ length = @window_size - @pos if @pos + length > @window_size
68
34
 
69
35
  # Fill a buffer with the data from the delegate.
70
- buffer = @io.read(length)
71
- # Error out if the end of the delegate is reached.
72
- raise EOFError, 'end of file reached' if buffer.nil?
36
+ result = super(length, buffer: buffer, buffer_offset: buffer_offset)
37
+ return result if Symbol === result
73
38
 
74
- # Update the position.
75
- @unbuffered_pos += buffer.length
39
+ @pos += buffer.nil? ? result.bytesize : result
76
40
 
77
- buffer
78
- ensure
79
- restore_delegate
41
+ result
80
42
  end
81
43
 
82
- def unbuffered_seek(offset, whence = IO::SEEK_SET)
83
- # Convert the offset and whence into an absolute position.
44
+ def seek(amount, whence = IO::SEEK_SET)
45
+ # Convert the amount into an absolute position.
84
46
  case whence
85
47
  when IO::SEEK_SET
86
- new_pos = offset
48
+ new_pos = amount
87
49
  when IO::SEEK_CUR
88
- new_pos = @unbuffered_pos + offset
50
+ new_pos = @pos + amount
89
51
  when IO::SEEK_END
90
- new_pos = @window_size + offset
52
+ new_pos = @window_size + amount
91
53
  end
92
54
 
93
55
  # Error out if the position is outside the window.
94
- raise Errno::EINVAL, 'Invalid argument' if new_pos < 0 or new_pos > @window_size
95
-
96
- # Set the new position.
97
- @unbuffered_pos = new_pos
98
- end
99
-
100
- # Restores the state of the delegate IO object to that saved by a prior call
101
- # to #restore_self.
102
- def restore_delegate
103
- @io.pos = @delegate_pos
104
- @io.lineno = @delegate_lineno
105
- end
56
+ if new_pos < 0 || new_pos > @window_size
57
+ raise Errno::EINVAL, 'Invalid argument'
58
+ end
106
59
 
107
- # Saves the state of the delegate IO object so that it can be restored later
108
- # using #restore_delegate and then configures the delegate so as to restore
109
- # the state of this object.
110
- def restore_self
111
- @delegate_pos = @io.pos
112
- @delegate_lineno = @io.lineno
113
- @io.pos = @window_position + @unbuffered_pos
60
+ @pos = super(new_pos + @window_position, IO::SEEK_SET) - @window_position
114
61
  end
115
62
  end
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'stringio'
4
+
5
+ ##
6
+ # This extends StringIO to include additional methods required by the io-like
7
+ # library to wrap IO objects.
8
+ class StringIO
9
+ unless public_method_defined?(:sysseek)
10
+ def sysseek(offset, whence = IO::SEEK_SET)
11
+ seek(offset, whence)
12
+ pos
13
+ end
14
+ end
15
+
16
+ unless public_method_defined?(:nonblock?)
17
+ def nonblock?
18
+ false
19
+ end
20
+ end
21
+
22
+ unless public_method_defined?(:wait)
23
+ def wait(*args)
24
+ return true
25
+ end
26
+ end
27
+ end