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 ADDED
@@ -0,0 +1,96 @@
1
+ IO::Buffer
2
+ ==========
3
+ [![Build Status](http://travis-ci.org/tarcieri/iobuffer.png)](http://travis-ci.org/tarcieri/iobuffer)
4
+
5
+ IO::Buffer is a fast byte queue which is primarily intended for non-blocking
6
+ I/O applications but is suitable wherever buffering is required. IO::Buffer
7
+ is compatible with Ruby 1.8/1.9 and Rubinius.
8
+
9
+ Usage
10
+ -----
11
+
12
+ IO::Buffer provides a subset of the methods available in Strings:
13
+
14
+ ```ruby
15
+ >> buf = IO::Buffer.new
16
+ => #<IO::Buffer:0x12fc708>
17
+ >> buf << "foo"
18
+ => "foo"
19
+ >> buf << "bar"
20
+ => "bar"
21
+ >> buf.to_str
22
+ => "foobar"
23
+ >> buf.size
24
+ => 6
25
+ ```
26
+
27
+ The IO::Buffer#<< method is an alias for IO::Buffer#append. A prepend method
28
+ is also available:
29
+
30
+ ```ruby
31
+ >> buf = IO::Buffer.new
32
+ => #<IO::Buffer:0x12f5250>
33
+ >> buf.append "bar"
34
+ => "bar"
35
+ >> buf.prepend "foo"
36
+ => "foo"
37
+ >> buf.append "baz"
38
+ => "baz"
39
+ >> buf.to_str
40
+ => "foobarbaz"
41
+ ```
42
+
43
+ IO::Buffer#read can be used to retrieve the contents of a buffer. You can mix
44
+ reads alongside adding more data to the buffer:
45
+
46
+ ```ruby
47
+ >> buf = IO::Buffer.new
48
+ => #<IO::Buffer:0x12fc5f0>
49
+ >> buf << "foo"
50
+ => "foo"
51
+ >> buf.read 2
52
+ => "fo"
53
+ >> buf << "bar"
54
+ => "bar"
55
+ >> buf.read 2
56
+ => "ob"
57
+ >> buf << "baz"
58
+ => "baz"
59
+ >> buf.read 3
60
+ => "arb"
61
+ ```
62
+
63
+ Finally, IO::Buffer provides methods for performing non-blocking I/O with the
64
+ contents of the buffer. The IO::Buffer#read_from(IO) method will read as much
65
+ data as possible from the given IO object until the read would block.
66
+
67
+ The IO::Buffer#write_to(IO) method writes the contents of the buffer to the
68
+ given IO object until either the buffer is empty or the write would block:
69
+
70
+ ```ruby
71
+ >> buf = IO::Buffer.new
72
+ => #<IO::Buffer:0x12fc5c8>
73
+ >> file = File.open("README")
74
+ => #<File:README>
75
+ >> buf.read_from(file)
76
+ => 1713
77
+ >> buf.to_str
78
+ => "= IO::Buffer\n\nIO::Buffer is a fast byte queue...
79
+ ```
80
+
81
+ If the file descriptor is not ready for I/O, the Errno::EAGAIN exception is
82
+ raised indicating no I/O was performed.
83
+
84
+ Contributing
85
+ ------------
86
+
87
+ * Fork this repository on github
88
+ * Make your changes and send me a pull request
89
+ * If I like them I'll merge them
90
+ * If I've accepted a patch, feel free to ask for commit access
91
+
92
+ License
93
+ -------
94
+
95
+ Copyright (c) 2007-12 Tony Arcieri. Distributed under the MIT License. See
96
+ LICENSE.txt for further details.