io-like 0.3.0 → 0.4.0.pre1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca93e63077fc81e1bf0bd7d8427525abf8b596f688b6e77c74435c97b0ee2b9e
4
+ data.tar.gz: 7a6db01e11f4c3801f55b6979cd20a996f4de0bd48d23e4712411c011bd8f64a
5
+ SHA512:
6
+ metadata.gz: 5953bc03797b4ed77f36471422a218c31fc3c974433e4fd73c22447f8febcda78be50bb7008b10521020ddea7a28c46fc18fa4633face34700ecb667dd0dda05
7
+ data.tar.gz: fbc480607dd5bb87c6c3697ea72df10af4c4fc3a5c2b1c6f6353f4a39b7f04e8d62ed5847c7dadd4a4dede2d6c1e0e0a39bbc77b599db171d7a6c2d1985bb013
data/LICENSE CHANGED
@@ -1,57 +1,22 @@
1
- LICENSE text follows:
2
-
3
- IO::Like is copyrighted free software by Jeremy Bopp
4
- <jeremy at bopp dot net>. You can redistribute it and/or modify it under
5
- either the terms of the GPL (see the included GPL file), or the conditions
6
- below:
7
-
8
- 1. You may make and give away verbatim copies of the source form of the
9
- software without restriction, provided that you duplicate all of the
10
- original copyright notices and associated disclaimers.
11
-
12
- 2. You may modify your copy of the software in any way, provided that
13
- you do at least ONE of the following:
14
-
15
- a) place your modifications in the Public Domain or otherwise
16
- make them Freely Available, such as by posting said
17
- modifications to Usenet or an equivalent medium, or by allowing
18
- the author to include your modifications in the software.
19
-
20
- b) use the modified software only within your corporation or
21
- organization.
22
-
23
- c) rename any non-standard executables so the names do not conflict
24
- with standard executables, which must also be provided.
25
-
26
- d) make other distribution arrangements with the author.
27
-
28
- 3. You may distribute the software in object code or executable
29
- form, provided that you do at least ONE of the following:
30
-
31
- a) distribute the executables and library files of the software,
32
- together with instructions (in the manual page or equivalent)
33
- on where to get the original distribution.
34
-
35
- b) accompany the distribution with the machine-readable source of
36
- the software.
37
-
38
- c) give non-standard executables non-standard names, with
39
- instructions on where to get the original software distribution.
40
-
41
- d) make other distribution arrangements with the author.
42
-
43
- 4. You may modify and include the covered part of the software into any
44
- other software (possibly commercial). But some files in the
45
- distribution may not be written by the author, such that they are not
46
- under these terms. (See the file LEGAL for a listing and conditions)
47
-
48
- 5. The scripts and library files supplied as input to or produced as
49
- output from the software do not automatically fall under the
50
- copyright of the software, but belong to whomever generated them,
51
- and may be sold commercially, and may be aggregated with this
52
- software.
53
-
54
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
- PURPOSE.
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024 Jeremy Bopp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/{NEWS → NEWS.md} RENAMED
@@ -1,30 +1,48 @@
1
- = News and Notifications by Version
1
+ # News and Notifications by Version
2
2
 
3
3
  This file lists noteworthy changes which may affect users of this project. More
4
4
  detailed information is available in the rest of the documentation.
5
5
 
6
- <b>NOTE:</b> Date stamps in the following entries are in YYYY/MM/DD format.
6
+ **NOTE:** Date stamps in the following entries are in YYYY/MM/DD format.
7
7
 
8
8
 
9
- == v0.3.0 (2009/04/29)
9
+ ## v0.4.0.pre1 (2025/05/07)
10
+ * Reimplemented all version specific IO::Like modules as a single class
11
+ * **WARNING:** Breaks API compatibility with prior versions
12
+ * Dropped support for Ruby less than 2.7
13
+ * Added full API compatibility for Ruby 2.7 through 3.4
14
+ * Support for character encodings
15
+ * Asynchronous/nonblocking methods
16
+ * Many missing helper methods
17
+ * Reworked spec handling to make it easier to import rubyspec snapshots almost
18
+ trivially (Grant Gardner, Jeremy Bopp)
19
+ * Added code coverage tooling
20
+
21
+
22
+ ## v0.3.1 (2020/02/09)
23
+
24
+ * Removed the rubyforge reference from the gemspec (Jordan Pickwell)
25
+
26
+
27
+ ## v0.3.0 (2009/04/29)
10
28
 
11
29
  * Fixed the rewind method to work with write-only streams
12
30
  * Fixed the read, gets, and readline methods to return partial data if they have
13
31
  such data but receive low level errors before reaching a stopping point
14
32
  * Renamed all private methods so that it is highly unlikely that they will be
15
- accidentally overridden.
33
+ accidentally overridden
16
34
  * Eliminated warnings caused by referencing uninitialized instance variables
17
35
  * Improved the documentation for the read, gets, and readline methods
18
36
 
19
37
 
20
- == v0.2.0 (2009/03/11)
38
+ ## v0.2.0 (2009/03/11)
21
39
 
22
40
  * Added mspec tests borrowed from the rubyspec project
23
41
  * Fixed many, many defects related to IO compatibility (Mostly obscure corner
24
42
  cases)
25
43
 
26
44
 
27
- == v0.1.0 (2008/07/03)
45
+ ## v0.1.0 (2008/07/03)
28
46
 
29
47
  * Initial release
30
48
  * All read, write, and seek functions implemented as defined in Ruby 1.8.6
data/README.md ADDED
@@ -0,0 +1,250 @@
1
+ # IO::Like - in the Likeness of IO
2
+
3
+ A composable implementation of IO methods.
4
+
5
+ ## LINKS
6
+
7
+ * Homepage :: http://github.com/javanthropus/io-like
8
+ * Documentation :: http://rdoc.info/gems/io-like/frames
9
+ * Source :: http://github.com/javanthropus/io-like
10
+
11
+ ## DESCRIPTION
12
+
13
+ This gem makes it possible to build filters or pipelines for processing data
14
+ into or out of streams of bytes while maintaining compatibility with native Ruby
15
+ IO classes. Ruby IO classes may function as both sources and sinks, or entirely
16
+ new IO implementations may be created.
17
+
18
+ ## FEATURES
19
+
20
+ * All standard Ruby 2.7 to 3.4 IO methods
21
+ * Primitive IO interfaces to facilitate creating IO filters/pipelines
22
+
23
+ ## KNOWN BUGS/LIMITATIONS
24
+
25
+ * None at this time
26
+
27
+ ## SYNOPSIS
28
+
29
+ More examples can be found in the `examples` directory of the source
30
+ distribution.
31
+
32
+ A simple ROT13 codec:
33
+
34
+ ```ruby
35
+ require 'io/like'
36
+ require 'io/like_helpers/delegated_io'
37
+ require 'io/like_helpers/io_wrapper'
38
+
39
+ include IO::LikeHelpers
40
+
41
+ class ROT13IO < IO::Like
42
+ def initialize(delegate, autoclose: true, **kwargs)
43
+ delegate = delegate.rot13_filter if self.class === delegate
44
+ @rot13_filter = ROT13Filter.new(delegate, autoclose: autoclose)
45
+
46
+ super(@rot13_filter, autoclose: true, **kwargs)
47
+ end
48
+
49
+ protected
50
+
51
+ def rot13_filter
52
+ flush if writable?
53
+ @rot13_filter
54
+ end
55
+ end
56
+
57
+ class ROT13Filter < DelegatedIO
58
+ def initialize(delegate, autoclose: true, **kwargs)
59
+ if IO === delegate
60
+ delegate = IOWrapper.new(delegate, autoclose: autoclose)
61
+ autoclose = true
62
+ end
63
+
64
+ super(delegate, autoclose: autoclose, **kwargs)
65
+ end
66
+
67
+ def read(length, buffer: nil, buffer_offset: 0)
68
+ result = super
69
+ if buffer.nil?
70
+ encode_rot13(result)
71
+ else
72
+ encode_rot13(buffer, buffer_offset: buffer_offset)
73
+ end
74
+ result
75
+ end
76
+
77
+ def write(buffer, length: buffer.bytesize)
78
+ super(encode_rot13(buffer[0, length]), length: length)
79
+ end
80
+
81
+ private
82
+
83
+ def encode_rot13(buffer, buffer_offset: 0)
84
+ buffer_offset.upto(buffer.length - 1) do |i|
85
+ ord = buffer[i].ord
86
+ case ord
87
+ when 65..90
88
+ buffer[i] = ((ord - 52) % 26 + 65).chr
89
+ when 97..122
90
+ buffer[i] = ((ord - 84) % 26 + 97).chr
91
+ end
92
+ end
93
+ buffer
94
+ end
95
+ end
96
+
97
+ if $0 == __FILE__
98
+ # Write encoded content to stdout, leaving stdout open after completion.
99
+ ROT13IO.open(STDOUT, autoclose: false) do |rot13|
100
+ rot13.puts('This is a test. 1234!') # -> Guvf vf n grfg. 1234!
101
+ end
102
+
103
+ # Decode content from an input stream and read as lines.
104
+ IO.pipe do |r, w|
105
+ w.puts('This is a test. 1234!')
106
+ w.puts('Guvf vf n grfg. 4567!')
107
+ w.close
108
+ ROT13IO.open(r) do |rot13|
109
+ puts(rot13.each_line.to_a.inspect) # -> ["Guvf vf n grfg. 1234!\n", "This is a test. 4567!\n"]
110
+ end
111
+ end
112
+
113
+ # Double decode content (noop) and dump to stdout using IO.copy_stream.
114
+ IO.pipe do |r, w|
115
+ w.puts('This is a test. 1234!')
116
+ w.close
117
+ ROT13IO.open(r) do |rot13|
118
+ ROT13IO.open(rot13) do |rot26|
119
+ IO.copy_stream(rot26, STDOUT) # -> This is a test. 1234!
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ # vim: ts=2 sw=2 et
126
+ ```
127
+
128
+ ## REQUIREMENTS
129
+
130
+ * None
131
+
132
+ ## INSTALL
133
+
134
+ $ gem install io-like
135
+
136
+ ## DEVELOPERS
137
+
138
+ After checking out the source, run:
139
+
140
+ $ bundle install
141
+ $ bundle exec rake test yard
142
+
143
+ This will install all dependencies, run the tests/specs, and generate the
144
+ documentation.
145
+
146
+ ## AUTHORS and CONTRIBUTORS
147
+
148
+ Thanks to all contributors. Without your help this project would not exist.
149
+
150
+ * Jeremy Bopp :: jeremy@bopp.net
151
+ * Jarred Holman :: jarred.holman@gmail.com
152
+ * Grant Gardner :: grant@lastweekend.com.au
153
+ * Jordan Pickwell :: jpickwell@users.noreply.github.com
154
+
155
+ ## CONTRIBUTING
156
+
157
+ Contributions for bug fixes, documentation, extensions, tests, etc. are
158
+ encouraged.
159
+
160
+ 1. Clone the repository.
161
+ 2. Fix a bug or add a feature.
162
+ 3. Add tests for the fix or feature.
163
+ 4. Make a pull request.
164
+
165
+ ### CODING STYLE
166
+
167
+ The following points are not necessarily set in stone but should rather be used
168
+ as a good guideline. Consistency is the goal of coding style, and changes will
169
+ be more easily accepted if they are consistent with the rest of the code.
170
+
171
+ * **File Encoding**
172
+ * UTF-8
173
+ * **Indentation**
174
+ * Two spaces; no tabs
175
+ * **Line length**
176
+ * Limit lines to a maximum of 80 characters
177
+ * **Comments**
178
+ * Document classes, attributes, methods, and code
179
+ * **Method Calls with Arguments**
180
+ * Use `a_method(arg, arg, etc)`; **not** `a_method( arg, arg, etc )`,
181
+ `a_method arg, arg, etc`, or any other variation
182
+ * **Method Calls without Arguments**
183
+ * Use `a_method`; avoid parenthesis
184
+ * **String Literals**
185
+ * Use single quotes by default
186
+ * Use double quotes when interpolation is necessary
187
+ * Use `%{...}` and similar when embedding the quoting character is cumbersome
188
+ * **Blocks**
189
+ * `do ... end` for multi-line blocks and `{ ... }` for single-line blocks
190
+ * **Boolean Operators**
191
+ * Use `&&` and `||` for boolean tests; avoid `and` and `or`
192
+ * **In General**
193
+ * Try to follow the flow and style of the rest of the code
194
+
195
+ ## LICENSE
196
+
197
+ ```
198
+ (The MIT License)
199
+
200
+ Copyright (c) 2024 Jeremy Bopp
201
+
202
+ Permission is hereby granted, free of charge, to any person obtaining
203
+ a copy of this software and associated documentation files (the
204
+ 'Software'), to deal in the Software without restriction, including
205
+ without limitation the rights to use, copy, modify, merge, publish,
206
+ distribute, sublicense, and/or sell copies of the Software, and to
207
+ permit persons to whom the Software is furnished to do so, subject to
208
+ the following conditions:
209
+
210
+ The above copyright notice and this permission notice shall be
211
+ included in all copies or substantial portions of the Software.
212
+
213
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
214
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
215
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
216
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
217
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
218
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
219
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
220
+ ```
221
+
222
+ ## RUBYSPEC LICENSE
223
+
224
+ Files under the `rubyspec` directory are copied in whole from the Rubyspec
225
+ project.
226
+
227
+ ```
228
+ Copyright (c) 2008 Engine Yard, Inc. All rights reserved.
229
+
230
+ Permission is hereby granted, free of charge, to any person
231
+ obtaining a copy of this software and associated documentation
232
+ files (the "Software"), to deal in the Software without
233
+ restriction, including without limitation the rights to use,
234
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
235
+ copies of the Software, and to permit persons to whom the
236
+ Software is furnished to do so, subject to the following
237
+ conditions:
238
+
239
+ The above copyright notice and this permission notice shall be
240
+ included in all copies or substantial portions of the Software.
241
+
242
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
243
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
244
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
245
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
246
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
247
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
248
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
249
+ OTHER DEALINGS IN THE SOFTWARE.
250
+ ```