iobuffer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +96 -0
- data/ext/iobuffer.c +490 -366
- data/lib/iobuffer/version.rb +5 -0
- metadata +57 -116
- data/CHANGES +0 -18
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -26
- data/LICENSE +0 -19
- data/README.rdoc +0 -83
- data/Rakefile +0 -74
- data/VERSION +0 -1
- data/ext/.gitignore +0 -4
- data/iobuffer.gemspec +0 -66
- data/lib/.gitignore +0 -1
- data/spec/buffer_spec.rb +0 -144
metadata
CHANGED
@@ -1,143 +1,84 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: iobuffer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tony Arcieri
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
name: rspec
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-02-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake-compiler
|
16
|
+
requirement: &70187477766020 !ruby/object:Gem::Requirement
|
26
17
|
none: false
|
27
|
-
requirements:
|
28
|
-
- -
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
segments:
|
32
|
-
- 2
|
33
|
-
- 1
|
34
|
-
- 0
|
35
|
-
version: 2.1.0
|
36
|
-
requirement: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
38
22
|
type: :development
|
39
23
|
prerelease: false
|
40
|
-
|
41
|
-
|
24
|
+
version_requirements: *70187477766020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70187477765400 !ruby/object:Gem::Requirement
|
42
28
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
segments:
|
48
|
-
- 1
|
49
|
-
- 0
|
50
|
-
- 0
|
51
|
-
version: 1.0.0
|
52
|
-
requirement: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
54
33
|
type: :development
|
55
34
|
prerelease: false
|
56
|
-
|
57
|
-
|
35
|
+
version_requirements: *70187477765400
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70187477764500 !ruby/object:Gem::Requirement
|
58
39
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
segments:
|
64
|
-
- 1
|
65
|
-
- 5
|
66
|
-
- 1
|
67
|
-
version: 1.5.1
|
68
|
-
requirement: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
70
44
|
type: :development
|
71
45
|
prerelease: false
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
- - ">="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
hash: 11
|
79
|
-
segments:
|
80
|
-
- 2
|
81
|
-
- 1
|
82
|
-
- 0
|
83
|
-
version: 2.1.0
|
84
|
-
requirement: *id004
|
85
|
-
description: iobuffer is a fast, C-based byte queue for storing arbitrary amounts of data until it can be written to the network
|
86
|
-
email: tony@medioh.com
|
46
|
+
version_requirements: *70187477764500
|
47
|
+
description: fast buffers for non-blocking IO
|
48
|
+
email:
|
49
|
+
- tony.arcieri@gmail.com
|
87
50
|
executables: []
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
-
|
93
|
-
- README.rdoc
|
94
|
-
files:
|
95
|
-
- CHANGES
|
96
|
-
- Gemfile
|
97
|
-
- Gemfile.lock
|
98
|
-
- LICENSE
|
99
|
-
- README.rdoc
|
100
|
-
- Rakefile
|
101
|
-
- VERSION
|
102
|
-
- ext/.gitignore
|
103
|
-
- ext/extconf.rb
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- README.md
|
55
|
+
- lib/iobuffer/version.rb
|
104
56
|
- ext/iobuffer.c
|
105
|
-
-
|
106
|
-
|
107
|
-
|
108
|
-
has_rdoc: true
|
109
|
-
homepage: http://github.com/tarcieri/iobuffer
|
110
|
-
licenses:
|
57
|
+
- ext/extconf.rb
|
58
|
+
homepage: https://github.com/tarcieri/iobuffer
|
59
|
+
licenses:
|
111
60
|
- MIT
|
112
61
|
post_install_message:
|
113
62
|
rdoc_options: []
|
114
|
-
|
115
|
-
require_paths:
|
63
|
+
require_paths:
|
116
64
|
- lib
|
117
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
66
|
none: false
|
119
|
-
requirements:
|
120
|
-
- -
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
|
123
|
-
|
124
|
-
- 0
|
125
|
-
version: "0"
|
126
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
72
|
none: false
|
128
|
-
requirements:
|
129
|
-
- -
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
|
132
|
-
segments:
|
133
|
-
- 0
|
134
|
-
version: "0"
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.6
|
135
77
|
requirements: []
|
136
|
-
|
137
78
|
rubyforge_project:
|
138
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.10
|
139
80
|
signing_key:
|
140
81
|
specification_version: 3
|
141
|
-
summary:
|
142
|
-
test_files:
|
143
|
-
|
82
|
+
summary: fast buffers for non-blocking IO
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|
data/CHANGES
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
0.1.3:
|
2
|
-
|
3
|
-
* Fix botched release :(
|
4
|
-
|
5
|
-
* Update gemspec so it only globs .c and .rb files, to prevent future
|
6
|
-
botched releases containing .o or .so files.
|
7
|
-
|
8
|
-
0.1.2:
|
9
|
-
|
10
|
-
* Tuneable node size
|
11
|
-
|
12
|
-
0.1.1:
|
13
|
-
|
14
|
-
* Ruby 1.8.7 compatibility fix
|
15
|
-
|
16
|
-
0.1.0:
|
17
|
-
|
18
|
-
* Initial release
|
data/Gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
group :development do
|
9
|
-
gem "rspec", ">= 2.1.0"
|
10
|
-
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.5.1"
|
12
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
diff-lcs (1.1.2)
|
5
|
-
git (1.2.5)
|
6
|
-
jeweler (1.5.1)
|
7
|
-
bundler (~> 1.0.0)
|
8
|
-
git (>= 1.2.5)
|
9
|
-
rake
|
10
|
-
rake (0.8.7)
|
11
|
-
rspec (2.2.0)
|
12
|
-
rspec-core (~> 2.2)
|
13
|
-
rspec-expectations (~> 2.2)
|
14
|
-
rspec-mocks (~> 2.2)
|
15
|
-
rspec-core (2.2.1)
|
16
|
-
rspec-expectations (2.2.0)
|
17
|
-
diff-lcs (~> 1.1.2)
|
18
|
-
rspec-mocks (2.2.0)
|
19
|
-
|
20
|
-
PLATFORMS
|
21
|
-
ruby
|
22
|
-
|
23
|
-
DEPENDENCIES
|
24
|
-
bundler (~> 1.0.0)
|
25
|
-
jeweler (~> 1.5.1)
|
26
|
-
rspec (>= 2.1.0)
|
data/LICENSE
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Copyright (C)2008 Tony Arcieri
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
= IO::Buffer
|
2
|
-
|
3
|
-
IO::Buffer is a fast byte queue which is primarily intended for non-blocking
|
4
|
-
I/O applications but is suitable wherever buffering is required. IO::Buffer
|
5
|
-
is compatible with Ruby 1.8.6+ and Ruby 1.9.0+
|
6
|
-
|
7
|
-
It was conceived for two reasons: it performs non-blocking buffered I/O
|
8
|
-
completely in C which removes the performance penalties associated with
|
9
|
-
implementing buffered I/O in pure Ruby, and also to mitigate performance
|
10
|
-
problems associated with M17N strings in Ruby 1.9.
|
11
|
-
|
12
|
-
== Usage
|
13
|
-
|
14
|
-
IO::Buffer provides a subset of the methods available in Strings:
|
15
|
-
|
16
|
-
>> buf = IO::Buffer.new
|
17
|
-
=> #<IO::Buffer:0x12fc708>
|
18
|
-
>> buf << "foo"
|
19
|
-
=> "foo"
|
20
|
-
>> buf << "bar"
|
21
|
-
=> "bar"
|
22
|
-
>> buf.to_str
|
23
|
-
=> "foobar"
|
24
|
-
>> buf.size
|
25
|
-
=> 6
|
26
|
-
|
27
|
-
The IO::Buffer#<< method is an alias for IO::Buffer#append. A prepend method
|
28
|
-
is also available:
|
29
|
-
|
30
|
-
>> buf = IO::Buffer.new
|
31
|
-
=> #<IO::Buffer:0x12f5250>
|
32
|
-
>> buf.append "bar"
|
33
|
-
=> "bar"
|
34
|
-
>> buf.prepend "foo"
|
35
|
-
=> "foo"
|
36
|
-
>> buf.append "baz"
|
37
|
-
=> "baz"
|
38
|
-
>> buf.to_str
|
39
|
-
=> "foobarbaz"
|
40
|
-
|
41
|
-
IO::Buffer#read can be used to retrieve the contents of a buffer. You can mix
|
42
|
-
reads alongside adding more data to the buffer:
|
43
|
-
|
44
|
-
>> buf = IO::Buffer.new
|
45
|
-
=> #<IO::Buffer:0x12fc5f0>
|
46
|
-
>> buf << "foo"
|
47
|
-
=> "foo"
|
48
|
-
>> buf.read 2
|
49
|
-
=> "fo"
|
50
|
-
>> buf << "bar"
|
51
|
-
=> "bar"
|
52
|
-
>> buf.read 2
|
53
|
-
=> "ob"
|
54
|
-
>> buf << "baz"
|
55
|
-
=> "baz"
|
56
|
-
>> buf.read 3
|
57
|
-
=> "arb"
|
58
|
-
|
59
|
-
Finally, IO::Buffer provides methods for performing non-blocking I/O with the
|
60
|
-
contents of the buffer. The IO::Buffer#read_from(IO) method will read as much
|
61
|
-
data as possible from the given IO object until the read would block.
|
62
|
-
|
63
|
-
The IO::Buffer#write_to(IO) method writes the contents of the buffer to the
|
64
|
-
given IO object until either the buffer is empty or the write would block:
|
65
|
-
|
66
|
-
>> buf = IO::Buffer.new
|
67
|
-
=> #<IO::Buffer:0x12fc5c8>
|
68
|
-
>> file = File.open("README")
|
69
|
-
=> #<File:README>
|
70
|
-
>> buf.read_from(file)
|
71
|
-
=> 1713
|
72
|
-
>> buf.to_str
|
73
|
-
=> "= IO::Buffer\n\nIO::Buffer is a fast byte queue...
|
74
|
-
|
75
|
-
If the file descriptor is not ready for I/O, the Errno::EAGAIN exception is
|
76
|
-
raised indicating no I/O was performed.
|
77
|
-
|
78
|
-
== History
|
79
|
-
|
80
|
-
IO::Buffer began its life as the buffer for Rev, a high performance event
|
81
|
-
library for Ruby.
|
82
|
-
|
83
|
-
As IO::Buffer has uses outside of Rev, it was spun off into its own Gem.
|
data/Rakefile
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
require 'rake/clean'
|
4
|
-
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "iobuffer"
|
18
|
-
gem.homepage = "http://github.com/tarcieri/iobuffer"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = "Fast C-based I/O buffering"
|
21
|
-
gem.description = "iobuffer is a fast, C-based byte queue for storing arbitrary amounts of data until it can be written to the network"
|
22
|
-
gem.email = "tony@medioh.com"
|
23
|
-
gem.authors = ["Tony Arcieri"]
|
24
|
-
|
25
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
26
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
27
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
28
|
-
|
29
|
-
gem.add_development_dependency 'rspec', '>= 2.1.0'
|
30
|
-
end
|
31
|
-
Jeweler::RubygemsDotOrgTasks.new
|
32
|
-
|
33
|
-
require 'rspec/core'
|
34
|
-
require 'rspec/core/rake_task'
|
35
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
36
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
37
|
-
spec.rspec_opts = %w(-fs -c)
|
38
|
-
end
|
39
|
-
|
40
|
-
task :default => [:compile, :spec]
|
41
|
-
|
42
|
-
require 'rake/rdoctask'
|
43
|
-
Rake::RDocTask.new do |rdoc|
|
44
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
-
|
46
|
-
rdoc.rdoc_dir = 'rdoc'
|
47
|
-
rdoc.title = "iobuffer #{version}"
|
48
|
-
rdoc.rdoc_files.include('README*')
|
49
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
-
end
|
51
|
-
|
52
|
-
ext_so = "ext/iobuffer.#{Config::MAKEFILE_CONFIG['DLEXT']}"
|
53
|
-
ext_files = FileList[
|
54
|
-
"ext/*.c",
|
55
|
-
"ext/*.h",
|
56
|
-
"ext/extconf.rb",
|
57
|
-
"ext/Makefile",
|
58
|
-
"lib"
|
59
|
-
]
|
60
|
-
|
61
|
-
desc "Compile the IO::Buffer extension"
|
62
|
-
task :compile => ["ext/Makefile", ext_so ]
|
63
|
-
|
64
|
-
file "ext/Makefile" => %w[ext/extconf.rb] do
|
65
|
-
Dir.chdir('ext') { ruby "extconf.rb" }
|
66
|
-
end
|
67
|
-
|
68
|
-
file ext_so => ext_files do
|
69
|
-
Dir.chdir('ext') { sh 'make' }
|
70
|
-
cp ext_so, "lib"
|
71
|
-
end
|
72
|
-
|
73
|
-
CLEAN.include ["**/*.o", "**/*.log", "pkg"]
|
74
|
-
CLEAN.include ["ext/Makefile", "**/iobuffer.#{Config::MAKEFILE_CONFIG['DLEXT']}"]
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.0
|
data/ext/.gitignore
DELETED
data/iobuffer.gemspec
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{iobuffer}
|
8
|
-
s.version = "1.0.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Tony Arcieri"]
|
12
|
-
s.date = %q{2010-12-15}
|
13
|
-
s.description = %q{iobuffer is a fast, C-based byte queue for storing arbitrary amounts of data until it can be written to the network}
|
14
|
-
s.email = %q{tony@medioh.com}
|
15
|
-
s.extensions = ["ext/extconf.rb"]
|
16
|
-
s.extra_rdoc_files = [
|
17
|
-
"LICENSE",
|
18
|
-
"README.rdoc"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
"CHANGES",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"LICENSE",
|
25
|
-
"README.rdoc",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"ext/.gitignore",
|
29
|
-
"ext/extconf.rb",
|
30
|
-
"ext/iobuffer.c",
|
31
|
-
"iobuffer.gemspec",
|
32
|
-
"lib/.gitignore",
|
33
|
-
"spec/buffer_spec.rb"
|
34
|
-
]
|
35
|
-
s.homepage = %q{http://github.com/tarcieri/iobuffer}
|
36
|
-
s.licenses = ["MIT"]
|
37
|
-
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.7}
|
39
|
-
s.summary = %q{Fast C-based I/O buffering}
|
40
|
-
s.test_files = [
|
41
|
-
"spec/buffer_spec.rb"
|
42
|
-
]
|
43
|
-
|
44
|
-
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
-
s.specification_version = 3
|
47
|
-
|
48
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_development_dependency(%q<rspec>, [">= 2.1.0"])
|
50
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
52
|
-
s.add_development_dependency(%q<rspec>, [">= 2.1.0"])
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<rspec>, [">= 2.1.0"])
|
55
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
57
|
-
s.add_dependency(%q<rspec>, [">= 2.1.0"])
|
58
|
-
end
|
59
|
-
else
|
60
|
-
s.add_dependency(%q<rspec>, [">= 2.1.0"])
|
61
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
63
|
-
s.add_dependency(%q<rspec>, [">= 2.1.0"])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
data/lib/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
iobuffer.*
|
data/spec/buffer_spec.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/iobuffer')
|
2
|
-
|
3
|
-
describe IO::Buffer do
|
4
|
-
before :each do
|
5
|
-
@buffer = IO::Buffer.new
|
6
|
-
@buffer.size.should == 0
|
7
|
-
end
|
8
|
-
|
9
|
-
it "appends data" do
|
10
|
-
@buffer.append "foo"
|
11
|
-
@buffer.size.should == 3
|
12
|
-
|
13
|
-
@buffer << "bar"
|
14
|
-
@buffer.size.should == 6
|
15
|
-
|
16
|
-
@buffer.write "baz"
|
17
|
-
@buffer.size.should == 9
|
18
|
-
|
19
|
-
@buffer.read.should == "foobarbaz"
|
20
|
-
@buffer.size.should == 0
|
21
|
-
end
|
22
|
-
|
23
|
-
it "prepends data" do
|
24
|
-
@buffer.prepend "foo"
|
25
|
-
@buffer.size.should == 3
|
26
|
-
|
27
|
-
@buffer.prepend "bar"
|
28
|
-
@buffer.size.should == 6
|
29
|
-
|
30
|
-
@buffer.read.should == "barfoo"
|
31
|
-
@buffer.size.should == 0
|
32
|
-
end
|
33
|
-
|
34
|
-
it "mixes prepending and appending properly" do
|
35
|
-
source_data = %w{foo bar baz qux}
|
36
|
-
actions = permutator([:append, :prepend] * 2)
|
37
|
-
|
38
|
-
actions.each do |sequence|
|
39
|
-
sequence.each_with_index do |entry, i|
|
40
|
-
@buffer.send(entry, source_data[i])
|
41
|
-
end
|
42
|
-
|
43
|
-
@buffer.size.should == sequence.size * 3
|
44
|
-
|
45
|
-
i = 0
|
46
|
-
expected = sequence.inject('') do |str, action|
|
47
|
-
case action
|
48
|
-
when :append
|
49
|
-
str << source_data[i]
|
50
|
-
when :prepend
|
51
|
-
str = source_data[i] + str
|
52
|
-
end
|
53
|
-
|
54
|
-
i += 1
|
55
|
-
str
|
56
|
-
end
|
57
|
-
|
58
|
-
@buffer.read.should == expected
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "reads data in chunks properly" do
|
63
|
-
@buffer.append "foobarbazqux"
|
64
|
-
|
65
|
-
@buffer.read(1).should == 'f'
|
66
|
-
@buffer.read(2).should == 'oo'
|
67
|
-
@buffer.read(3).should == 'bar'
|
68
|
-
@buffer.read(4).should == 'bazq'
|
69
|
-
@buffer.read(1).should == 'u'
|
70
|
-
@buffer.read(2).should == 'x'
|
71
|
-
end
|
72
|
-
|
73
|
-
it "converts to a string" do
|
74
|
-
@buffer.append "foobar"
|
75
|
-
@buffer.to_str == "foobar"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "clears data" do
|
79
|
-
@buffer.append "foo"
|
80
|
-
@buffer.prepend "bar"
|
81
|
-
|
82
|
-
@buffer.clear
|
83
|
-
@buffer.size.should == 0
|
84
|
-
@buffer.read.should == ""
|
85
|
-
|
86
|
-
@buffer.prepend "foo"
|
87
|
-
@buffer.prepend "bar"
|
88
|
-
@buffer.append "baz"
|
89
|
-
|
90
|
-
@buffer.clear
|
91
|
-
@buffer.size.should == 0
|
92
|
-
@buffer.read.should == ""
|
93
|
-
end
|
94
|
-
|
95
|
-
it "knows when it's empty" do
|
96
|
-
@buffer.should be_empty
|
97
|
-
@buffer.append "foo"
|
98
|
-
@buffer.should_not be_empty
|
99
|
-
end
|
100
|
-
|
101
|
-
it "can set default node size" do
|
102
|
-
IO::Buffer.default_node_size = 1
|
103
|
-
IO::Buffer.default_node_size.should == 1
|
104
|
-
(IO::Buffer.default_node_size = 4096).should == 4096
|
105
|
-
end
|
106
|
-
|
107
|
-
it "can be created with a different node size" do
|
108
|
-
IO::Buffer.new(16384)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "cannot set invalid node sizes" do
|
112
|
-
proc {
|
113
|
-
IO::Buffer.default_node_size = 0xffffffffffffffff
|
114
|
-
}.should raise_error(RangeError)
|
115
|
-
proc {
|
116
|
-
IO::Buffer.default_node_size = 0
|
117
|
-
}.should raise_error(ArgumentError)
|
118
|
-
proc {
|
119
|
-
IO::Buffer.new(0xffffffffffffffff)
|
120
|
-
}.should raise_error(RangeError)
|
121
|
-
proc {
|
122
|
-
IO::Buffer.new(0)
|
123
|
-
}.should raise_error(ArgumentError)
|
124
|
-
end
|
125
|
-
|
126
|
-
#######
|
127
|
-
private
|
128
|
-
#######
|
129
|
-
|
130
|
-
def permutator(input)
|
131
|
-
output = []
|
132
|
-
return output if input.empty?
|
133
|
-
|
134
|
-
(0..input.size - 1).inject([]) do |a, n|
|
135
|
-
if a.empty?
|
136
|
-
input.each { |x| output << [x] }
|
137
|
-
else
|
138
|
-
input.each { |x| output += a.map { |y| [x, *y] } }
|
139
|
-
end
|
140
|
-
|
141
|
-
output.dup
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|