line_buffer 1.0.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 +7 -0
- data/lib/line_buffer.rb +29 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 48658b62ba43adb17558eb1f2b4a387ee9fc0c37
|
|
4
|
+
data.tar.gz: 49c94f23b965b92a7d454ae9129005c36e444380
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 172d07e91882081a191304954bf19715c2cec2d9fc4c8f72ce702957415bfc0f0125ef7cf5d2c044f5bdecdc57337ee06dca31b22d659b33455c36fff8a01a2c
|
|
7
|
+
data.tar.gz: 8687fef03cec45bf43b3cbda652c18d542a5034e10baa5f2701a56e21b9ba765acedaf471da72ea8fd60046e3fd95c40f854a88860fe3ed4ccc2c94d191f3cca
|
data/lib/line_buffer.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class LineBuffer
|
|
2
|
+
def initialize(options = {})
|
|
3
|
+
@encoding = options[:encoding] || DEFAULT_ENCODING
|
|
4
|
+
@buffer = ''.force_encoding(Encoding::BINARY)
|
|
5
|
+
@cut_offset = @index_offset = 0
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def <<(chunk)
|
|
9
|
+
@buffer << chunk
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get(&block)
|
|
13
|
+
@buffer.force_encoding(Encoding::BINARY)
|
|
14
|
+
while (i = @buffer.index(NEWLINE, @index_offset))
|
|
15
|
+
yield @buffer[@cut_offset, i-@cut_offset+1].force_encoding(@encoding)
|
|
16
|
+
@index_offset = @cut_offset = i+1
|
|
17
|
+
end
|
|
18
|
+
@buffer.slice!(0, @cut_offset)
|
|
19
|
+
@index_offset = @buffer.size
|
|
20
|
+
@cut_offset = 0
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def done?
|
|
24
|
+
@buffer.empty?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
NEWLINE = "\n".force_encoding(Encoding::BINARY).freeze
|
|
28
|
+
DEFAULT_ENCODING = Encoding::UTF_8
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: line_buffer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Erik Fonselius
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-11-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A ruby implementation of yielding lines when streaming data to a buffer
|
|
14
|
+
email: fonsan@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/line_buffer.rb
|
|
20
|
+
homepage: https://github.com/Fonsan/line_buffer
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.6.12
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: LineBuffer
|
|
44
|
+
test_files: []
|
|
45
|
+
has_rdoc:
|