io-stream 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e86dd2d0db65582e6b9655493776e1f3fa16c8d22af92d40c7c2f1ae374c7ee
4
- data.tar.gz: e6299a23d03c263361f04bae8ec29c3d0b70c2f19d6cdfe64ff601d6b7bb7c64
3
+ metadata.gz: 6d85df6aecb7833dd6945292040cb635510f088df8dc0f9427b207ada1b8fcfa
4
+ data.tar.gz: 07b3d70a28adc36c23286f42f92c0d9eec99a3a176efbbb839c3f4c9d34a13fd
5
5
  SHA512:
6
- metadata.gz: 16d2aff35b208b029c2b917cd6a423d5ee54547939a39e5575f2641d8060b793a03a5a0903a885216142d99369ba80f8941d35ab07739a11c95d2c98dfa1d3cd
7
- data.tar.gz: af90134348a217f72fe90dea4cab0c2c4e7fc6b7a2c27345b865642191c9aa0bdda16b2e1856114d1e42bbf7f9c6be7bb506daa8cb9724baae2fdf1534dcc85e
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,8 +153,8 @@ 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
@@ -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?
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
 
6
6
  module IO::Stream
7
- VERSION = "0.4.3"
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.3
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-02 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