io-extra 1.4.0 → 1.5.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +22 -17
- data/Gemfile +2 -0
- data/LICENSE +177 -0
- data/{MANIFEST → MANIFEST.md} +4 -4
- data/README.md +114 -0
- data/Rakefile +102 -0
- data/certs/djberg96_pub.pem +26 -0
- data/doc/io_extra.txt +85 -0
- data/examples/example_io_extra.rb +53 -0
- data/examples/example_pread.rb +24 -0
- data/examples/writev_benchmark.rb +19 -0
- data/ext/extra.bundle.dSYM/Contents/Info.plist +20 -0
- data/ext/extra.bundle.dSYM/Contents/Resources/Relocations/aarch64/extra.bundle.yml +5 -0
- data/ext/io/extra.c +172 -81
- data/io-extra.gemspec +51 -0
- data/lib/io-extra.rb +3 -1
- data/spec/io_extra_spec.rb +179 -0
- data.tar.gz.sig +0 -0
- metadata +74 -15
- metadata.gz.sig +0 -0
- data/README +0 -97
- data/test/test_io_extra.rb +0 -148
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7411da9ba5734ed08fc6678a9d715629a6873593533835f54fcadda0349ac718
|
|
4
|
+
data.tar.gz: d4e87cac61878af96b99030777a02870329b5180abce8eb8b4a4033217bf480f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 55b9ce62dac9906bc9b75c2033395a8185894baa0f31eabe681dda4fc76bd59c5ed566975a86c890138176e9ae37b424d2aaeaf8124b5f60c8c610fe11cc6fe1
|
|
7
|
+
data.tar.gz: 8f1dd271f9046af836f2024f1e8857e71ab21542d2c56b8dfd861a8c681f092c6e69cfefa259d5ef77e78934e0478357d674637ac50b0bd11917b7fcb34c8bc5
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/{CHANGES → CHANGES.md}
RENAMED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
## 1.5.0 - 8-Jan-2026
|
|
2
|
+
* The fdwalk method now works on MacOS.
|
|
3
|
+
* Lots of internal refactoring in general, mostly for the writev method,
|
|
4
|
+
but also stuff like CI updates, rubocop suggestions, etc.
|
|
5
|
+
|
|
6
|
+
## 1.4.0 - 8-Jul-2020
|
|
2
7
|
* Replaced the C versions of IO.pread and IO.pwrite singleton methods with
|
|
3
8
|
pure Ruby wrappers since core Ruby has implemented instance method versions
|
|
4
9
|
since Ruby 2.5. These now require filehandles (rather than fileno) as an
|
|
@@ -11,7 +16,7 @@
|
|
|
11
16
|
* Added a LICENSE file as required by the Apache-2.0 license.
|
|
12
17
|
* The 'io-extra' file is now the preferred way to require this library.
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
## 1.3.0 - 19-Oct-2018
|
|
15
20
|
* Now assumes Ruby 2.1 or later. This has no effect on the external API, but
|
|
16
21
|
it does allow for lots of internal cleanup.
|
|
17
22
|
* License changed to Apache-2.0.
|
|
@@ -22,10 +27,10 @@
|
|
|
22
27
|
* Added a cert.
|
|
23
28
|
* Removed the .gemtest file.
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
## 1.2.8 - 29-Dec-2014
|
|
26
31
|
* Updated for compatibility with Ruby 2.2.x.
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
## 1.2.7 - 10-Aug-2013
|
|
29
34
|
* Direct IO is now supported on Darwin, and some bugs in the directio
|
|
30
35
|
methods have been fixed. Thanks go to Genki Takiuchi for the patches.
|
|
31
36
|
* Fixed a bug in fdwalk and closefrom when using Ruby 1.9.3 where
|
|
@@ -36,42 +41,42 @@
|
|
|
36
41
|
* The rb_thread_call_without_gvl function is now used internally in
|
|
37
42
|
place of rb_thread_blocking_region for Ruby 2.x.
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
## 1.2.6 - 22-May-2011
|
|
40
45
|
* Fixed a potential memory leak in the pread_ptr method where malloc'ed
|
|
41
46
|
memory was not freed if the pread function call failed. Thanks go to
|
|
42
47
|
Eric Wong for the spot.
|
|
43
48
|
* Added the IO#ttyname method.
|
|
44
49
|
* Added the (empty) .gemtest file for test.rubygems.org.
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
## 1.2.5 - 23-Mar-2011
|
|
47
52
|
* Use rb_thread_blocking_region internally for IO.pread and IO.pwrite. Thanks
|
|
48
53
|
go to Eric Wong for the patch.
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
## 1.2.4 - 22-Mar-2011
|
|
51
56
|
* Use NUM2OFFT where appropriate. Fixes potential 32 vs 64 bit issues. Thanks
|
|
52
57
|
go to Eric Wong for the spot and patch.
|
|
53
58
|
* Added an example program for IO.pread, and a corresponding Rake task.
|
|
54
59
|
* Config substituted with RbConfig, since the former is apparently going to
|
|
55
60
|
deprecated in 1.9. Thanks go to Eric Wong for the spot and patch.
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
## 1.2.3 - 25-Oct-2010
|
|
58
63
|
* Documentation updates to the README.
|
|
59
64
|
* Updates to the Rakefile, including archive tasks, a default task, and
|
|
60
65
|
tweaks to the clean task.
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
## 1.2.2 - 1-May-2010
|
|
63
68
|
* Added the IO.writev method which allows you to write arrays without
|
|
64
69
|
requiring an Array#join call, i.e. "gather write". Thanks go to Eric
|
|
65
70
|
Wong for supplying the code to support this.
|
|
66
71
|
* Some Rakefile updates.
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
## 1.2.1 - 16-Jan-2010
|
|
69
74
|
* Some README updates
|
|
70
75
|
* Updates to the gemspec.
|
|
71
76
|
* Added the gem:build and gem:install rake task.
|
|
72
77
|
* Source code moved to github.
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
## 1.2.0 - 28-Jul-2009
|
|
75
80
|
* Several Linux compatibility fixes, all provided by Eric Wong.
|
|
76
81
|
* Now compatible with 1.9.x thanks to Eric Wong.
|
|
77
82
|
* Bug fix for IO.pread - memory leak and null byte behavior spotted and
|
|
@@ -81,19 +86,19 @@
|
|
|
81
86
|
* Several tests were updated to use features from test-unit 2.x.
|
|
82
87
|
* Fixed the 'example' rake task.
|
|
83
88
|
|
|
84
|
-
|
|
89
|
+
## 1.1.1 - 8-Sep-2008
|
|
85
90
|
* Added the IO.pread_ptr method. This returns the buffer address
|
|
86
91
|
rather than the buffer itself.
|
|
87
92
|
* Added limited support for OS X.
|
|
88
93
|
* Minor refactoring of the IO.pread method.
|
|
89
94
|
|
|
90
|
-
|
|
95
|
+
## 1.1.0 - 28-Aug-2008
|
|
91
96
|
* Added IO.pread and IO.pwrite methods for those platforms that
|
|
92
97
|
support them.
|
|
93
98
|
* Fixed a warning that could occur in the IO#directio method.
|
|
94
99
|
* Some updates the README, CHANGES, and test files.
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
## 1.0.2 - 16-Jul-2007
|
|
97
102
|
* Added a Rakefile with tasks for testing and installation.
|
|
98
103
|
* Some doc updates and internal reorganization, but no significant code
|
|
99
104
|
changes.
|
|
@@ -101,13 +106,13 @@
|
|
|
101
106
|
mistaken about the header file I should use).
|
|
102
107
|
* Minor updates to the example program.
|
|
103
108
|
|
|
104
|
-
|
|
109
|
+
## 1.0.1 - 7-Jul-2006
|
|
105
110
|
* Added a gemspec.
|
|
106
111
|
* Added or improved the inline rdoc comments in the source.
|
|
107
112
|
|
|
108
|
-
|
|
113
|
+
## 1.0.0 - 16-Jun-2005
|
|
109
114
|
* Moved project to RubyForge.
|
|
110
115
|
* Added a CHANGES file.
|
|
111
116
|
|
|
112
|
-
|
|
117
|
+
## 0.1.0 - 26-Jan-2005
|
|
113
118
|
* Initial release
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
data/{MANIFEST → MANIFEST.md}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
* CHANGES
|
|
1
|
+
* CHANGES.md
|
|
2
2
|
* LICENSE
|
|
3
|
-
* MANIFEST
|
|
4
|
-
* README
|
|
3
|
+
* MANIFEST.md
|
|
4
|
+
* README.md
|
|
5
5
|
* Rakefile
|
|
6
6
|
* io-extra.gemspec
|
|
7
7
|
* certs/djberg96_pub.pem
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* ext/extconf.rb
|
|
11
11
|
* ext/io/extra.c
|
|
12
12
|
* lib/io-extra.rb
|
|
13
|
-
*
|
|
13
|
+
* spec/io_extra_spec.rb
|
data/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
[](https://github.com/djberg96/io-extra/actions/workflows/ruby.yml)
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
The io-extra library provides a few extra IO methods that you may find
|
|
5
|
+
handy. They are `IO.closefrom`, `IO.fdwalk`, `IO.pread`, `IO.pwrite`,
|
|
6
|
+
`IO.writev`, `IO#directio?` and `IO#directio=`.
|
|
7
|
+
|
|
8
|
+
This library is not supported on MS Windows.
|
|
9
|
+
|
|
10
|
+
Support for OS X is limited. See below for details.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
`gem install io-extra`
|
|
14
|
+
|
|
15
|
+
## Adding the trusted cert
|
|
16
|
+
`gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/io-extra/main/certs/djberg96_pub.pem)`
|
|
17
|
+
|
|
18
|
+
## Synopsis
|
|
19
|
+
```ruby
|
|
20
|
+
require 'io-extra' # Do not use 'io/extra'
|
|
21
|
+
|
|
22
|
+
# Close all file descriptors from 3 up.
|
|
23
|
+
IO.closefrom(3)
|
|
24
|
+
|
|
25
|
+
# Inspect all the open handles
|
|
26
|
+
IO.fdwalk(0){ |handle|
|
|
27
|
+
puts "=" * 40
|
|
28
|
+
p handle
|
|
29
|
+
p handle.fileno
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Write an array to an IO object efficiently
|
|
33
|
+
IO.writev(fh.fileno, %w[a b c])
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Developer's Notes
|
|
37
|
+
The "require 'io-extra'" is preferred over 'io/extra' because this is a mix
|
|
38
|
+
of pure Ruby and C extension. The former require's the latter, so that way
|
|
39
|
+
you get all the methods and constants that you expect.
|
|
40
|
+
|
|
41
|
+
You might be wondering what the difference is between my implementation of
|
|
42
|
+
`IO.closefrom` and a pure Ruby version that looks something like this:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
def IO.closefrom(n)
|
|
46
|
+
0.upto(n) do |fd|
|
|
47
|
+
IO.for_fd(fd).close
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The primary difference is that this walks all file descriptors, rather
|
|
53
|
+
than only open file descriptors. However, I should note that this only
|
|
54
|
+
applies if your platform supports the `closefrom()` function. In that case,
|
|
55
|
+
the only advantage is speed.
|
|
56
|
+
|
|
57
|
+
You might also be wondering what the difference is between my implementation
|
|
58
|
+
of IO.fdwalk and a pure Ruby version that looks something like this:
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
def IO.fdwalk(n)
|
|
62
|
+
ObjectSpace.each_object(File){ |f|
|
|
63
|
+
yield f if f.fileno >= n
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The primary difference is that this only closes Ruby file objects, not
|
|
69
|
+
necessarily every file handle opened by the Ruby process. For example,
|
|
70
|
+
handles opened via `system()` calls.
|
|
71
|
+
|
|
72
|
+
## Note to OS X Users
|
|
73
|
+
The OS X platform does not support `closefrom()` or `fdwalk()`. The hand-
|
|
74
|
+
crafted `IO.closefrom` function will not work because the `getrlimit()`
|
|
75
|
+
function on OS X does not work. Patches welcome.
|
|
76
|
+
|
|
77
|
+
## Update regarding pread and pwrite
|
|
78
|
+
As of Ruby 2.5, the `IO#pread` and `IO#pwrite` instance methods have been
|
|
79
|
+
baked into the language. Consequently, the singleton methods that this
|
|
80
|
+
library originally provided are now just wrappers around those instance
|
|
81
|
+
methods.
|
|
82
|
+
|
|
83
|
+
## Documentation
|
|
84
|
+
For further documentation, see the io_extra.txt file or the inline
|
|
85
|
+
documentation that was generated by RDoc (if you did a gem install).
|
|
86
|
+
|
|
87
|
+
## Known Issues
|
|
88
|
+
The `IO.writev` tests fail on Solaris. Short test scripts seem to work,
|
|
89
|
+
however. We're not sure what the issue is yet. Help wanted.
|
|
90
|
+
|
|
91
|
+
Update: As of 2018 Solaris is basically dead, so I'm not going to worry
|
|
92
|
+
about supporting Solaris unless there's an outcry.
|
|
93
|
+
|
|
94
|
+
Please file any bug reports on the project page at
|
|
95
|
+
https://github.com/djberg96/io-extra
|
|
96
|
+
|
|
97
|
+
## Acknowledgements
|
|
98
|
+
Eric Wong for some great work on Linux compatibility and other fixes, as
|
|
99
|
+
well as the code for the IO.writev method.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
Apache-2.0
|
|
103
|
+
|
|
104
|
+
## Copyright
|
|
105
|
+
(C) 2003-2026 Daniel J. Berger
|
|
106
|
+
All Rights Reserved
|
|
107
|
+
|
|
108
|
+
## Warranty
|
|
109
|
+
This package is provided "as is" and without any express or
|
|
110
|
+
implied warranties, including, without limitation, the implied
|
|
111
|
+
warranties of merchantability and fitness for a particular purpose.
|
|
112
|
+
|
|
113
|
+
## Author
|
|
114
|
+
Daniel J. Berger
|
data/Rakefile
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/clean'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
require 'rubocop/rake_task'
|
|
5
|
+
require 'rbconfig'
|
|
6
|
+
include RbConfig
|
|
7
|
+
|
|
8
|
+
CLEAN.include(
|
|
9
|
+
'**/*.gem', # Gem files
|
|
10
|
+
'**/*.rbc', # Rubinius
|
|
11
|
+
'**/*.o', # C object file
|
|
12
|
+
'**/*.log', # Ruby extension build log
|
|
13
|
+
'**/*.lock', # Gemfile.lock
|
|
14
|
+
'**/Makefile', # C Makefile
|
|
15
|
+
'**/conftest.dSYM', # OS X build directory
|
|
16
|
+
"**/*.#{CONFIG['DLEXT']}" # C shared object
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if File::ALT_SEPARATOR
|
|
20
|
+
STDERR.puts 'Not supported on this platform. Exiting.'
|
|
21
|
+
exit(-1)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
desc "Build the io-extra library (but don't install it)"
|
|
25
|
+
task :build => [:clean] do
|
|
26
|
+
Dir.chdir('ext') do
|
|
27
|
+
ruby 'extconf.rb'
|
|
28
|
+
sh 'make'
|
|
29
|
+
build_file = File.join(Dir.pwd, 'extra.' + CONFIG['DLEXT'])
|
|
30
|
+
Dir.mkdir('io') unless File.exist?('io')
|
|
31
|
+
FileUtils.cp(build_file, 'io')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
namespace :gem do
|
|
36
|
+
desc 'Create the io-extra gem'
|
|
37
|
+
task :create => [:clean] do
|
|
38
|
+
require 'rubygems/package'
|
|
39
|
+
spec = Gem::Specification.load('io-extra.gemspec')
|
|
40
|
+
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
|
41
|
+
Gem::Package.build(spec)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc "Install the io-extra library as a gem"
|
|
45
|
+
task :install => [:create] do
|
|
46
|
+
file = Dir["io-extra*.gem"].last
|
|
47
|
+
sh "gem install -l #{file}"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
namespace :archive do
|
|
52
|
+
spec = eval(IO.read('io-extra.gemspec'))
|
|
53
|
+
file = "io-extra-#{spec.version}"
|
|
54
|
+
|
|
55
|
+
desc 'Create an io-extra tarball.'
|
|
56
|
+
task :tar do
|
|
57
|
+
file = file + ".tar"
|
|
58
|
+
cmd = "git archive --format=tar --prefix=#{file}/ -o #{file} HEAD"
|
|
59
|
+
sh cmd
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
desc 'Create a gzipped tarball for io-extra'
|
|
63
|
+
task :gz => [:tar] do
|
|
64
|
+
sh "gzip #{file}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
desc 'Create a bzip2 tarball for io-extra'
|
|
68
|
+
task :bz2 => [:tar] do
|
|
69
|
+
sh "bzip2 #{file}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
desc 'Create a zipped tarball for io-extra'
|
|
73
|
+
task :zip do
|
|
74
|
+
sh "git archive --format=zip --prefix=#{file}/ -o #{file}.zip HEAD"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
desc "Run the example io-extra program"
|
|
79
|
+
task :example => [:build] do
|
|
80
|
+
ruby '-Iext examples/example_io_extra.rb'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
namespace :example do
|
|
84
|
+
desc "Run the IO.pread example program."
|
|
85
|
+
task :pread => [:build] do
|
|
86
|
+
ruby '-Iext examples/example_pread.rb'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
desc "Run the test suite"
|
|
91
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
92
|
+
t.rspec_opts = '-Iext -f documentation'
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Clean up afterwards
|
|
96
|
+
Rake::Task[:spec].enhance do
|
|
97
|
+
Rake::Task[:clean].invoke
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
RuboCop::RakeTask.new
|
|
101
|
+
|
|
102
|
+
task :default => [:build, :spec]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
|
|
3
|
+
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
|
4
|
+
MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
|
|
5
|
+
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
|
6
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
|
|
7
|
+
A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
|
|
8
|
+
u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
|
|
9
|
+
75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
|
|
10
|
+
6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
|
|
11
|
+
iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
|
|
12
|
+
ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
|
|
13
|
+
74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
|
|
14
|
+
058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
|
|
15
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
|
|
16
|
+
AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
|
|
17
|
+
YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
|
|
18
|
+
/3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
|
|
19
|
+
h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
|
|
20
|
+
6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
|
|
21
|
+
ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
|
|
22
|
+
1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
|
|
23
|
+
DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
|
|
24
|
+
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
|
25
|
+
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
|
26
|
+
-----END CERTIFICATE-----
|
data/doc/io_extra.txt
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
= Description
|
|
2
|
+
The io-extra library provides a few extra IO methods that you may find
|
|
3
|
+
handy.
|
|
4
|
+
|
|
5
|
+
= Supported Platforms
|
|
6
|
+
Works on most Unix platforms.
|
|
7
|
+
|
|
8
|
+
Not supported on MS Windows or OS X.
|
|
9
|
+
|
|
10
|
+
= Synopsis
|
|
11
|
+
require "io/extra"
|
|
12
|
+
|
|
13
|
+
# Print the fileno of each file handle and then close it
|
|
14
|
+
IO.fdwalk(0){ |fh|
|
|
15
|
+
p fh.fileno
|
|
16
|
+
fh.close
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Close all file handles with a fileno greater than or equal to 2.
|
|
20
|
+
IO.closefrom(2)
|
|
21
|
+
|
|
22
|
+
= Class Methods
|
|
23
|
+
IO.closefrom(low_fd)
|
|
24
|
+
Closes all open file descriptors greater than or equal to 'low_fd'.
|
|
25
|
+
|
|
26
|
+
This uses your systems native closefrom() function, if supported. If not,
|
|
27
|
+
this method uses a slightly less efficient manual approach that uses
|
|
28
|
+
getrlimit() behind the scenes.
|
|
29
|
+
|
|
30
|
+
IO.fdwalk(low_fd){ |fh| ... }
|
|
31
|
+
Iterates over each open file descriptor and yields back a File object.
|
|
32
|
+
Note that it is up to you to close file handles, if desired, when this
|
|
33
|
+
method is used.
|
|
34
|
+
|
|
35
|
+
Not supported on all platforms.
|
|
36
|
+
|
|
37
|
+
IO.pread(fd, length, offset)
|
|
38
|
+
Reads +length+ bytes of data from the given +fd+, starting at +offset.
|
|
39
|
+
The primary advantage of this method over Ruby's IO#read method is that
|
|
40
|
+
it performs the read without changing the file pointer.
|
|
41
|
+
|
|
42
|
+
Not supported on all platforms.
|
|
43
|
+
|
|
44
|
+
IO.pwrite(fd, buf, offset)
|
|
45
|
+
Writes +buf+ to the given +fd+, starting at +offset. The primary advantage
|
|
46
|
+
of this method over a standard seek & write approach is that it performs
|
|
47
|
+
the write without changing the file pointer.
|
|
48
|
+
|
|
49
|
+
Not supported on all platforms.
|
|
50
|
+
|
|
51
|
+
= Instance methods
|
|
52
|
+
IO#directio?
|
|
53
|
+
Returns true or false, based on whether directio has been set for the
|
|
54
|
+
current handle. The default is false.
|
|
55
|
+
|
|
56
|
+
Note supported on all platforms.
|
|
57
|
+
|
|
58
|
+
IO#directio=(io_const)
|
|
59
|
+
Sets the advice for the current file descriptor using directio(). Valid
|
|
60
|
+
values are IO::DIRECTIO_ON and IO::DIRECTIO_OFF.
|
|
61
|
+
|
|
62
|
+
All file descriptors start at DIRECTIO_OFF, unless your filesystem has
|
|
63
|
+
been mounted using 'forcedirectio' (and supports that option).
|
|
64
|
+
|
|
65
|
+
Not supported on all platforms
|
|
66
|
+
|
|
67
|
+
= Constants
|
|
68
|
+
IO::DIRECTIO_ON
|
|
69
|
+
This value can be passed to IO#directio= in order to turn directio on for
|
|
70
|
+
the given file handle.
|
|
71
|
+
|
|
72
|
+
This value is only defined if your platform supports the directio()
|
|
73
|
+
function.
|
|
74
|
+
IO::DIRECTIO_OFF
|
|
75
|
+
This value can be passed to IO#directio= in order to turn directio off for
|
|
76
|
+
the given file handle.
|
|
77
|
+
|
|
78
|
+
This value is only defined if your platform supports the directio()
|
|
79
|
+
function.
|
|
80
|
+
|
|
81
|
+
IO::EXTRA_VERSION
|
|
82
|
+
Returns the current version number of this library as a String.
|
|
83
|
+
|
|
84
|
+
= Other documentation
|
|
85
|
+
See the README for more documentation.
|