event_stream_parser 0.1.0 → 0.3.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: 498814773bcffd664024e918c1f94e32393e6b8af266fe88084cadb4cd8c86d7
4
- data.tar.gz: da45b31afcb41e23bb2fb4dbde9d0c5ed173d8fb8ac0759464129528b19e49bd
3
+ metadata.gz: 830b3472c8f361af6b3e3fe2b3d405be779a188dfad03689d742e1c7432c9d9a
4
+ data.tar.gz: 136a34302cc7b8ac6de60307960258fac2618035ad66394867417481f8c76437
5
5
  SHA512:
6
- metadata.gz: 2123d8df807cb4cb1a3f1981f3bd3d59eec2393579d4c41bc7a4f597be6f827e285ef8cffb37abfd12d9266e69febe5be09ad79f7dff53ef288c950ffc077603
7
- data.tar.gz: dbadc0f0bc184c0d08f8e6466f4384ce51baf25da1d97bbc90ba75a0d92f3a48468dc82882015f82d17d5f047d64625ddffe8897a51dd7b8e972a19b3d585fbb
6
+ metadata.gz: 1834aa3df2243b44538415a4e05b4cc4cf2a86132a48ad32b70c12994205866fa3f80a530e75573b204d1d3cfc2719928f92fa13ddd9db868d6fbdee5f9d241e
7
+ data.tar.gz: 3b6b3bc90c9353988bc906b6fdec21e54d6bd3762f5f386d7cbfff4688fb7df0a626e5f3d8f054d8957f1c170d2bdb98295815887d278b84d0b82907b47ed96f
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # event_stream_parser
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/event_stream_parser.svg)](https://badge.fury.io/rb/event_stream_parser)
4
+ [![CI](https://github.com/Shopify/event_stream_parser/actions/workflows/ci.yml/badge.svg)](https://github.com/Shopify/event_stream_parser/actions/workflows/ci.yml)
5
+
3
6
  A lightweight, fully spec-compliant parser for the
4
7
  [event stream](https://www.w3.org/TR/eventsource/) format.
5
8
 
@@ -11,6 +14,8 @@ from an HTTP client, for example) and emits events as it parses them. But it
11
14
  remembers the last event id and reconnection time and keeps emitting them as
12
15
  long as they are not overwritten by new ones.
13
16
 
17
+ BOM stripping is left as a responsibility of the chunk provider.
18
+
14
19
  ## Installation
15
20
 
16
21
  Add this line to your application's Gemfile:
@@ -74,11 +79,7 @@ After checking out the repo:
74
79
  2. Run `rake test` to run the tests.
75
80
  3. Run `rubocop` to run Rubocop.
76
81
 
77
- To install this gem onto your local machine, run `bundle exec rake install`. To
78
- release a new version, update the version number in `version.rb`, and then run
79
- `bundle exec rake release`, which will create a git tag for the version, push
80
- git commits and tags, and push the `.gem` file to
81
- [rubygems.org](https://rubygems.org).
82
+ To install this gem onto your local machine, run `bundle exec rake install`.
82
83
 
83
84
  ## Contributing
84
85
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStreamParser
4
- VERSION = "0.1.0"
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "event_stream_parser/version"
3
+ require 'event_stream_parser/version'
4
4
 
5
5
  module EventStreamParser
6
6
  ##
@@ -12,34 +12,22 @@ module EventStreamParser
12
12
  # Code comments are copied from the spec.
13
13
  #
14
14
  class Parser
15
- UTF_8_BOM = [0xEF, 0xBB, 0xBF].pack("C*").force_encoding("UTF-8").freeze
16
-
17
15
  def initialize
18
16
  ##
19
17
  # When a stream is parsed, a data buffer, an event type buffer, and a last
20
18
  # event ID buffer must be associated with it. They must be initialized to
21
19
  # the empty string.
22
20
  #
23
- @data_buffer = +""
24
- @event_type_buffer = +""
25
- @last_event_id_buffer = +""
21
+ @data_buffer = +''
22
+ @event_type_buffer = +''
23
+ @last_event_id_buffer = +''
26
24
 
27
25
  @reconnection_time = nil
28
- @buffer = +""
29
- @first_chunk = true
26
+ @buffer = +''
30
27
  @last_delimiter = nil
31
28
  end
32
29
 
33
30
  def feed(chunk, &proc)
34
- ##
35
- # The UTF-8 decode algorithm strips one leading UTF-8 Byte Order Mark (BOM),
36
- # if any.
37
- #
38
- if @first_chunk
39
- chunk = chunk.delete_prefix(UTF_8_BOM)
40
- @first_chunk = false
41
- end
42
-
43
31
  @buffer << chunk
44
32
 
45
33
  ##
@@ -50,9 +38,7 @@ module EventStreamParser
50
38
  # followed by a U+000A LINE FEED (LF) character being the ways in which a
51
39
  # line can end.
52
40
  #
53
- if @last_delimiter == "\r"
54
- @buffer.delete_prefix!("\n")
55
- end
41
+ @buffer.delete_prefix!("\n") if @last_delimiter == "\r"
56
42
 
57
43
  while (line = @buffer.slice!(/.*?(?<delim>\r\n|\r|\n)/))
58
44
  line.chomp!
@@ -80,7 +66,7 @@ module EventStreamParser
80
66
  ##
81
67
  # If the line is empty (a blank line)
82
68
  #
83
- when ""
69
+ when ''
84
70
  ##
85
71
  # Dispatch the event, as defined below.
86
72
  #
@@ -118,7 +104,7 @@ module EventStreamParser
118
104
  # Process the field using the steps described below, using the whole line
119
105
  # as the field name, and the empty string as the field value.
120
106
  #
121
- process_field(line, "")
107
+ process_field(line, '')
122
108
  end
123
109
  end
124
110
 
@@ -132,7 +118,7 @@ module EventStreamParser
132
118
  ##
133
119
  # If the field name is "event"
134
120
  #
135
- when "event"
121
+ when 'event'
136
122
  ##
137
123
  # Set the event type buffer to field value.
138
124
  #
@@ -140,7 +126,7 @@ module EventStreamParser
140
126
  ##
141
127
  # If the field name is "data"
142
128
  #
143
- when "data"
129
+ when 'data'
144
130
  ##
145
131
  # Append the field value to the data buffer, then append a single U+000A
146
132
  # LINE FEED (LF) character to the data buffer.
@@ -149,7 +135,7 @@ module EventStreamParser
149
135
  ##
150
136
  # If the field name is "id"
151
137
  #
152
- when "id"
138
+ when 'id'
153
139
  ##
154
140
  # If the field value does not contain U+0000 NULL, then set the last event
155
141
  # ID buffer to the field value. Otherwise, ignore the field.
@@ -158,7 +144,7 @@ module EventStreamParser
158
144
  ##
159
145
  # If the field name is "retry"
160
146
  #
161
- when "retry"
147
+ when 'retry'
162
148
  ##
163
149
  # If the field value consists of only ASCII digits, then interpret the
164
150
  # field value as an integer in base ten, and set the event stream's
@@ -200,8 +186,8 @@ module EventStreamParser
200
186
  # event type buffer to the empty string and return.
201
187
  #
202
188
  if @data_buffer.empty?
203
- @data_buffer = +""
204
- @event_type_buffer = +""
189
+ @data_buffer = +''
190
+ @event_type_buffer = +''
205
191
  return
206
192
  end
207
193
  ##
@@ -225,8 +211,8 @@ module EventStreamParser
225
211
  ##
226
212
  # 7. Set the data buffer and the event type buffer to the empty string.
227
213
  #
228
- @data_buffer = +""
229
- @event_type_buffer = +""
214
+ @data_buffer = +''
215
+ @event_type_buffer = +''
230
216
 
231
217
  yield type, data, id, @reconnection_time
232
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_stream_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ates Goral
@@ -9,35 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-10-16 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '5.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '13.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '13.0'
12
+ dependencies: []
41
13
  description:
42
14
  email:
43
15
  - ates.goral@shopify.com
@@ -54,7 +26,11 @@ homepage: https://github.com/Shopify/event_stream_parser
54
26
  licenses:
55
27
  - MIT
56
28
  metadata:
29
+ bug_tracker_uri: https://github.com/Shopify/event_stream_parser/issues
30
+ changelog_uri: https://github.com/Shopify/event_stream_parser/blob/main/CHANGELOG.md
31
+ source_code_uri: https://github.com/Shopify/event_stream_parser
57
32
  allowed_push_host: https://rubygems.org
33
+ rubygems_mfa_required: 'true'
58
34
  post_install_message:
59
35
  rdoc_options: []
60
36
  require_paths:
@@ -63,7 +39,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
39
  requirements:
64
40
  - - ">="
65
41
  - !ruby/object:Gem::Version
66
- version: 2.7.0
42
+ version: 2.6.0
67
43
  required_rubygems_version: !ruby/object:Gem::Requirement
68
44
  requirements:
69
45
  - - ">="