io-stream 0.4.2 → 0.5.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: fe1cb88a44b5750ca8841631a3031da7ff06004e21d5dccf319012f0a0f1151f
4
- data.tar.gz: 30d66da77b2887c16024511e907a8b30fdf1b24c53ee548f3a9171b54ff45ee1
3
+ metadata.gz: 6d85df6aecb7833dd6945292040cb635510f088df8dc0f9427b207ada1b8fcfa
4
+ data.tar.gz: 07b3d70a28adc36c23286f42f92c0d9eec99a3a176efbbb839c3f4c9d34a13fd
5
5
  SHA512:
6
- metadata.gz: e2ad4475b779c7c421fb7143fac491243790e210c12dac89d37e885753353c78d1305bd08144e12204a13d4c068c7cf16a9133462fe0a5f19a5eecd49e839fc7
7
- data.tar.gz: edef464bbf54fdfd662850aca4b7fcc522caca32566a2201b2ee8c68460c5eff9ae67d5e645e255b2e60ba951b88d10703648393e65c4f1b58f12ccffc8cd6cb
6
+ metadata.gz: e40a994276d5cab512b1c77213ba48c02fe7916256c0070893f37bc641baea4ecf277ee3695b76357617b6e5366ddb22fbf8ff5839f7c64698edc01b3bc2ced9
7
+ data.tar.gz: 21ae83634d2c036a2c60865fdafb26de516fc8a0822c45ff018fd6c887079c73dcb63ace72f07b316d87b5973b4de5d3d673d435a89f09c755361ab0a63238ce
checksums.yaml.gz.sig CHANGED
Binary file
@@ -86,9 +86,11 @@ module IO::Stream
86
86
  end
87
87
 
88
88
  # Efficiently read data from the stream until encountering pattern.
89
- # @param pattern [String] The pattern to match.
90
- # @return [String] The contents of the stream up until the pattern, which is consumed but not returned.
91
- def read_until(pattern, offset = 0, chomp: true)
89
+ # @parameter pattern [String] The pattern to match.
90
+ # @parameter offset [Integer] The offset to start searching from.
91
+ # @parameter limit [Integer] The maximum number of bytes to read, including the pattern (even if chomped).
92
+ # @returns [String | Nil] The contents of the stream up until the pattern, which is consumed but not returned.
93
+ def read_until(pattern, offset = 0, limit: nil, chomp: true)
92
94
  # We don't want to split on the pattern, so we subtract the size of the pattern.
93
95
  split_offset = pattern.bytesize - 1
94
96
 
@@ -97,9 +99,12 @@ module IO::Stream
97
99
 
98
100
  offset = 0 if offset < 0
99
101
 
100
- return unless fill_read_buffer
102
+ return nil if limit and offset >= limit
103
+ return nil unless fill_read_buffer
101
104
  end
102
105
 
106
+ return nil if limit and index >= limit
107
+
103
108
  @read_buffer.freeze
104
109
  matched = @read_buffer.byteslice(0, index+(chomp ? 0 : pattern.bytesize))
105
110
  @read_buffer = @read_buffer.byteslice(index+pattern.bytesize, @read_buffer.bytesize)
@@ -148,13 +153,13 @@ module IO::Stream
148
153
 
149
154
  # Writes `string` to the buffer. When the buffer is full or #sync is true the
150
155
  # buffer is flushed to the underlying `io`.
151
- # @param string the string to write to the buffer.
152
- # @return the number of bytes appended to the buffer.
156
+ # @parameter string [String] the string to write to the buffer.
157
+ # @returns [Integer] the number of bytes appended to the buffer.
153
158
  def write(string, flush: false)
154
159
  @writing.synchronize do
155
160
  @write_buffer << string
156
161
 
157
- flush |= @write_buffer.bytesize >= @block_size
162
+ flush |= (@write_buffer.bytesize >= @block_size)
158
163
 
159
164
  if flush
160
165
  self.drain(@write_buffer)
@@ -292,7 +297,7 @@ module IO::Stream
292
297
  end
293
298
 
294
299
  # Consumes at most `size` bytes from the buffer.
295
- # @param size [Integer|nil] The amount of data to consume. If nil, consume entire buffer.
300
+ # @parameter size [Integer|nil] The amount of data to consume. If nil, consume entire buffer.
296
301
  def consume_read_buffer(size = nil)
297
302
  # If we are at eof, and the read buffer is empty, we can't consume anything.
298
303
  return nil if @eof && @read_buffer.empty?
@@ -43,6 +43,18 @@ module OpenSSL
43
43
  to_io.timeout = value
44
44
  end
45
45
  end
46
+
47
+ unless method_defined?(:buffered?)
48
+ def buffered?
49
+ return to_io.buffered?
50
+ end
51
+ end
52
+
53
+ unless method_defined?(:buffered=)
54
+ def buffered=(value)
55
+ to_io.buffered = value
56
+ end
57
+ end
46
58
  end
47
59
  end
48
60
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
 
6
6
  module IO::Stream
7
- VERSION = "0.4.2"
7
+ VERSION = "0.5.0"
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-10-01 00:00:00.000000000 Z
40
+ date: 2024-10-14 00:00:00.000000000 Z
41
41
  dependencies: []
42
42
  description:
43
43
  email:
metadata.gz.sig CHANGED
Binary file