minitar 1.1.1 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7855c77e89244e7288b4bb9398593ea6ac680a3891f3e9ce0bda77a8ea5f2e48
4
- data.tar.gz: 1c2d05408cc0d2a69b604e257ec032bdbd98efd5384198a0b0d47f78e1407a31
3
+ metadata.gz: 4d63d57bffbc9767103b43d388bc963d21328b552fc8d24931cc3a038dfd3711
4
+ data.tar.gz: '0853ab22f6156d7b7ff8a0f3c1eb2751471937b2afc61a722114a9f950297ebc'
5
5
  SHA512:
6
- metadata.gz: 01dd7962ebc29dcdfa69221b6ece851f4ad488b1c9f25cd546054a611ec90f9ae3f44a7a3d0555f9efb7927a71f9c59cba75729bd46b103e4a8b4ead52e46547
7
- data.tar.gz: 58e66377d5e593c6be0c149ac392931affea945c03fc12b34262fe5fa6154edd24247aa2ad7008b37891c12002199e664b8fe4875833b70d961492b8a42b2628
6
+ metadata.gz: c3f0aa730db48594ec62b100f48cc76915fcabe72a0bfd52d9c10d27f82360d1913e604e06d330cf9d0704568812eea2d26b23332c56b7ebe6ffedba7c1cad11
7
+ data.tar.gz: 2b3a18c4c3ca23ddef71bdfd97cdf67a4e3ce03bae23f81389c247b0b1ed4e64e1863dba73a8739ec7e16687f82f78ec1ddf62114d44750e897747cddca4b050
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 / 2026-11-11
4
+
5
+ - Enhancements:
6
+
7
+ - Richard Degenne extended `Minitar::Reader::EntryStream#read` to accept a
8
+ second parameter, `out_string`, where the data read from the stream will
9
+ be read. [#166][pull-166]
10
+
11
+ - Documentation:
12
+
13
+ - Removed duplicate documentation files and updated the RDoc to match the
14
+ configuration.
15
+
3
16
  ## 1.1.1 / 2026-11-11
4
17
 
5
18
  - Security:
@@ -33,11 +46,6 @@
33
46
  Names such as `dirname../file` were previously rejected incorrectly on all
34
47
  platforms.
35
48
 
36
- - Documentation:
37
-
38
- - Removed duplicate documentation files and updated the RDoc to match the
39
- configuration.
40
-
41
49
  ## 1.1.0 / 2025-09-07
42
50
 
43
51
  - Enhancements:
@@ -323,4 +331,5 @@
323
331
  [pull-43]: https://github.com/halostatue/minitar/pull/43
324
332
  [pull-47]: https://github.com/halostatue/minitar/pull/47
325
333
  [pull-121]: https://github.com/halostatue/minitar/pull/121
334
+ [pull-166]: https://github.com/halostatue/minitar/pull/166
326
335
  [tidelift]: https://tidelift.com/security
@@ -51,13 +51,25 @@ class Minitar::Reader
51
51
  end
52
52
  end
53
53
 
54
- # Reads `len` bytes (or all remaining data) from the entry. Returns `nil` if there
55
- # is no more data to read.
56
- def read(len = nil)
54
+ # Reads `len` bytes (or all remaining data) from the entry. If `out_string`
55
+ # is provided, the read data is stored there instead of allocating a new
56
+ # string. Returns `nil` if there is no more data to read.
57
+ def read(len = nil, out_string = nil)
57
58
  return nil if @read >= @size
58
59
  len ||= @size - @read
59
60
  max_read = [len, @size - @read].min
60
- ret = @io.read(max_read)
61
+
62
+ ret =
63
+ if out_string
64
+ begin
65
+ @io.read(max_read, out_string)
66
+ rescue ArgumentError # If `@io` does not support `out_string`
67
+ out_string.replace(@io.read(max_read))
68
+ end
69
+ else
70
+ @io.read(max_read)
71
+ end
72
+
61
73
  @read += ret.bytesize
62
74
  ret
63
75
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Minitar
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -28,7 +28,7 @@ class TestTarReader < Minitest::Test
28
28
  sizes = [10, 0, 0, 0]
29
29
  isdir = [false, false, true, true]
30
30
  isfile = [true, true, false, false]
31
- Minitar::Reader.new(StringIO.new(str)) do |is|
31
+ Minitar::Reader.open(StringIO.new(str)) do |is|
32
32
  i = 0
33
33
  is.each_entry do |entry|
34
34
  assert_kind_of Minitar::Reader::EntryStream, entry
@@ -54,7 +54,7 @@ class TestTarReader < Minitest::Test
54
54
  str = build_tar_file_header("lib/foo", "", 0o10644, content.bytesize) +
55
55
  content + "\0" * (512 - content.bytesize)
56
56
  str << "\0" * 1024
57
- Minitar::Reader.new(StringIO.new(str)) do |is|
57
+ Minitar::Reader.open(StringIO.new(str)) do |is|
58
58
  is.each_entry do |entry|
59
59
  3.times do
60
60
  entry.rewind
@@ -70,7 +70,7 @@ class TestTarReader < Minitest::Test
70
70
  str = build_tar_file_header("lib/foo", "", 0o10644, content.bytesize) +
71
71
  content + "\0" * (512 - content.bytesize)
72
72
  str << "\0" * 1024
73
- Minitar::Reader.new(StringIO.new(str)) do |is|
73
+ Minitar::Reader.open(StringIO.new(str)) do |is|
74
74
  3.times do
75
75
  is.rewind
76
76
  i = 0
@@ -87,7 +87,7 @@ class TestTarReader < Minitest::Test
87
87
  contents = ("a".."z").inject(+"") { |a, e| a << e * 100 }
88
88
  str = build_tar_file_header("lib/foo", "", 0o10644, contents.bytesize) + contents
89
89
  str += "\0" * (512 - (str.bytesize % 512))
90
- Minitar::Reader.new(StringIO.new(str)) do |is|
90
+ Minitar::Reader.open(StringIO.new(str)) do |is|
91
91
  is.each_entry do |entry|
92
92
  assert_kind_of Minitar::Reader::EntryStream, entry
93
93
  data = entry.read(3000) # bigger than contents.bytesize
@@ -95,7 +95,7 @@ class TestTarReader < Minitest::Test
95
95
  assert entry.eof?
96
96
  end
97
97
  end
98
- Minitar::Reader.new(StringIO.new(str)) do |is|
98
+ Minitar::Reader.open(StringIO.new(str)) do |is|
99
99
  is.each_entry do |entry|
100
100
  assert_kind_of Minitar::Reader::EntryStream, entry
101
101
  data = entry.read(100)
@@ -105,7 +105,7 @@ class TestTarReader < Minitest::Test
105
105
  assert entry.eof?
106
106
  end
107
107
  end
108
- Minitar::Reader.new(StringIO.new(str)) do |is|
108
+ Minitar::Reader.open(StringIO.new(str)) do |is|
109
109
  is.each_entry do |entry|
110
110
  assert_kind_of Minitar::Reader::EntryStream, entry
111
111
  data = entry.read
@@ -116,11 +116,19 @@ class TestTarReader < Minitest::Test
116
116
  assert entry.eof?
117
117
  end
118
118
  end
119
+ Minitar::Reader.open(StringIO.new(str)) do |is|
120
+ is.each_entry do |entry|
121
+ assert_kind_of Minitar::Reader::EntryStream, entry
122
+ buffer = +""
123
+ entry.read(nil, buffer)
124
+ assert_equal contents, buffer
125
+ end
126
+ end
119
127
  end
120
128
 
121
129
  def test_eof_works
122
130
  str = build_tar_file_header("bar", "baz", 0o644, 0)
123
- Minitar::Reader.new(StringIO.new(str)) do |is|
131
+ Minitar::Reader.open(StringIO.new(str)) do |is|
124
132
  is.each_entry do |entry|
125
133
  assert_kind_of Minitar::Reader::EntryStream, entry
126
134
  data = entry.read
@@ -132,7 +140,7 @@ class TestTarReader < Minitest::Test
132
140
  end
133
141
  end
134
142
  str = build_tar_dir_header("foo", "bar", 0o12345)
135
- Minitar::Reader.new(StringIO.new(str)) do |is|
143
+ Minitar::Reader.open(StringIO.new(str)) do |is|
136
144
  is.each_entry do |entry|
137
145
  assert_kind_of Minitar::Reader::EntryStream, entry
138
146
  data = entry.read
@@ -146,7 +154,7 @@ class TestTarReader < Minitest::Test
146
154
  str = build_tar_dir_header("foo", "bar", 0o12345)
147
155
  str += build_tar_file_header("bar", "baz", 0o644, 0)
148
156
  str += build_tar_file_header("bar", "baz", 0o644, 0)
149
- Minitar::Reader.new(StringIO.new(str)) do |is|
157
+ Minitar::Reader.open(StringIO.new(str)) do |is|
150
158
  is.each_entry do |entry|
151
159
  assert_kind_of Minitar::Reader::EntryStream, entry
152
160
  data = entry.read
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Ziegler