protocol-http 0.38.0 → 0.40.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: 95fdcce85b20ee97e54b44068d59f689f040d1c9489b0e2ff8f9e63464d4c7cd
4
- data.tar.gz: a72f51087a046f2f713208baace1631414e32b1e2eceb82ff69d479b2c2a7eac
3
+ metadata.gz: 10e80047df314ab51026467f51437b52b9c09efda85f028ae1835f5e8ff4ae6c
4
+ data.tar.gz: '08c4a65646072f0e229cbd096a10d7c3f701d5c72edb17c5f9ee2cc112d574bb'
5
5
  SHA512:
6
- metadata.gz: a4e7504cf962c63a5dac26fbd235b50d6796d5c97eb1f4b40be4cf6023fd1e118a8c64254d1199cab94f1086ad608367e1e4932de1836d63986b2548149fb3b7
7
- data.tar.gz: b88389e903b175e65fa9f1ee2e36b4894d0484475d8f999ab001cf4968c6edbafb1f9a75fbf14f7fad5f1c7d8e2b4b40a55fd2070aa19ac9eb0a4aae785fdbec
6
+ metadata.gz: 2a7c1dcdeffbf00442217783b7b01a93ae866b1471a1441729931cc485d5eef491c03fb22b2a5ee05dfcf87c4818be41706cb10abe78f37de6dd4187f9d75fb6
7
+ data.tar.gz: 778915a18c596ff9ebb21f2d0b5bc6da4f59de7248d1ac08ee3dddaa9526a8b17de6fb93b002fe048ed4b842370d161499eaaf1d70aeb7dd4fe41281dc8ed90e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -18,6 +18,7 @@ module Protocol
18
18
 
19
19
  def initialize(file, range = nil, size: file.size, block_size: BLOCK_SIZE)
20
20
  @file = file
21
+ @range = range
21
22
 
22
23
  @block_size = block_size
23
24
 
@@ -26,6 +27,7 @@ module Protocol
26
27
  @offset = range.min
27
28
  @length = @remaining = range.size
28
29
  else
30
+ @file.seek(0)
29
31
  @offset = 0
30
32
  @length = @remaining = size
31
33
  end
@@ -51,11 +53,19 @@ module Protocol
51
53
  true
52
54
  end
53
55
 
56
+ def buffered
57
+ self.class.new(@file.dup, @range, block_size: @block_size)
58
+ end
59
+
54
60
  def rewind
55
61
  @file.seek(@offset)
56
62
  @remaining = @length
57
63
  end
58
64
 
65
+ def rewindable?
66
+ true
67
+ end
68
+
59
69
  def read
60
70
  if @remaining > 0
61
71
  amount = [@remaining, @block_size].min
@@ -191,9 +191,63 @@ module Protocol
191
191
  # Read a single line from the stream.
192
192
  #
193
193
  # @parameter separator [String] The line separator, defaults to `\n`.
194
+ # @parameter limit [Integer] The maximum number of bytes to read.
194
195
  # @parameter *options [Hash] Additional options, passed to {read_until}.
195
- def gets(separator = NEWLINE, **options)
196
- read_until(separator, **options)
196
+ def gets(separator = NEWLINE, limit = nil, chomp: false)
197
+ # If the separator is an integer, it is actually the limit:
198
+ if separator.is_a?(Integer)
199
+ limit = separator
200
+ separator = NEWLINE
201
+ end
202
+
203
+ # If no separator is given, this is the same as a read operation:
204
+ if separator.nil?
205
+ return read(limit)
206
+ end
207
+
208
+ # We don't want to split on the separator, so we subtract the size of the separator:
209
+ split_offset = separator.bytesize - 1
210
+
211
+ @buffer ||= read_next
212
+ return nil if @buffer.nil?
213
+
214
+ offset = 0
215
+ until index = @buffer.index(separator, offset)
216
+ offset = @buffer.bytesize - split_offset
217
+ offset = 0 if offset < 0
218
+
219
+ # If we have gone past the limit, we are done:
220
+ if limit and offset >= limit
221
+ @buffer.freeze
222
+ matched = @buffer.byteslice(0, limit)
223
+ @buffer = @buffer.byteslice(limit, @buffer.bytesize)
224
+ return matched
225
+ end
226
+
227
+ # Read more data:
228
+ if chunk = read_next
229
+ @buffer << chunk
230
+ else
231
+ # No more data could be read, return the remaining data:
232
+ buffer = @buffer
233
+ @buffer = nil
234
+
235
+ return @buffer
236
+ end
237
+ end
238
+
239
+ # Freeze the buffer, as this enables us to use byteslice without generating a hidden copy:
240
+ @buffer.freeze
241
+
242
+ if limit and index > limit
243
+ line = @buffer.byteslice(0, limit)
244
+ @buffer = @buffer.byteslice(limit, @buffer.bytesize)
245
+ else
246
+ line = @buffer.byteslice(0, index+(chomp ? 0 : separator.bytesize))
247
+ @buffer = @buffer.byteslice(index+separator.bytesize, @buffer.bytesize)
248
+ end
249
+
250
+ return line
197
251
  end
198
252
  end
199
253
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.38.0"
8
+ VERSION = "0.40.0"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- .�>5 0ϊ��Mu}� �ـND-/GJ�Bd��t(�$SU� �Nn�"�3�/ 44a�#�4�jW�X:ʋ����m��T �FH�D]�g����+W<�_�w�w�~}�� 8�#����'��'}V�| soz ��>I���I&�q %�5��a�]\��^�A�x�.v-~��M���,B` >���}"u����
2
- � O&c#�r�"�5��0�gx���t�k{�>�\::v�ju����s�ŷ�2]�W��[iq��,�p��רڟ&�s=4n�=�ۅq�ɍ)�(�F�u�GvT8�5�C�pXL~�:� ��e���Y�+�,�����/�Iߐ��x�,@E�Љ�|����:�V��`��Q
1
+ I1a�����g}nm�"�KL�+VJC%���t��k�e}s}�*�xٻ3c79��d�-:���i�,Z����+0%�𐟟�<�R"E�|�w 5��AM���'z��bc��sG]B]b���ڍ�I+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.38.0
4
+ version: 0.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -47,7 +47,7 @@ cert_chain:
47
47
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
48
48
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
49
49
  -----END CERTIFICATE-----
50
- date: 2024-10-14 00:00:00.000000000 Z
50
+ date: 2024-10-16 00:00:00.000000000 Z
51
51
  dependencies: []
52
52
  description:
53
53
  email:
metadata.gz.sig CHANGED
Binary file