bychar 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bychar.gemspec +1 -1
  2. data/lib/bychar.rb +7 -7
  3. metadata +2 -2
data/bychar.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bychar"
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
data/lib/bychar.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'stringio'
3
3
 
4
4
  module Bychar
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.1'
6
6
 
7
7
  # Default buffer size is 512k
8
8
  DEFAULT_BUFFER_SIZE = 512 * 1024
@@ -19,31 +19,31 @@ module Bychar
19
19
  def initialize(with_io, buffer_size = DEFAULT_BUFFER_SIZE)
20
20
  @io = with_io
21
21
  @bufsize = buffer_size
22
- @buf = StringIO.new
22
+ cache
23
23
  end
24
24
 
25
25
  # Will transparently read one byte off the contained IO, maintaining the internal cache.
26
26
  # If the cache has been depleted it will read a big chunk from the IO and cache it and then
27
27
  # return the byte
28
28
  def read_one_byte
29
- cache if @buf.pos == @buf.size
29
+ cache if @buf.nil? || @buf.eos?
30
30
 
31
- return nil if @buf.size.zero?
32
- return @buf.read(1)
31
+ return nil if @buf.eos?
32
+ return @buf.getch
33
33
  end
34
34
 
35
35
  # Tells whether all the data has been both read from the passed buffer
36
36
  # and from the internal cache buffer (checks whether there is anything that
37
37
  # can be retreived using read_one_byte)
38
38
  def eof?
39
- @buf.eof? && @io.eof?
39
+ (@buf && @buf.eos?) && @io.eof?
40
40
  end
41
41
 
42
42
  private
43
43
 
44
44
  def cache
45
45
  data = @io.read(@bufsize)
46
- @buf = StringIO.new(data.to_s) # Make nil become ""
46
+ @buf = StringScanner.new(data.to_s) # Make nil become ""
47
47
  end
48
48
  end
49
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bychar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: -3036736534217565560
110
+ hash: 1325391043988314358
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  none: false
113
113
  requirements: