io-extra 1.2.5 → 1.4.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.
@@ -0,0 +1,17 @@
1
+ require 'io/extra'
2
+
3
+ class IO
4
+ EXTRA_VERSION = '1.4.0'.freeze
5
+
6
+ # Singleton version of the IO#pwrite method.
7
+ #
8
+ def self.pwrite(fd, string, offset)
9
+ fd.pwrite(string, offset)
10
+ end
11
+
12
+ # Singleton version of the IO#pread method.
13
+ #
14
+ def self.pread(fd, maxlen, offset)
15
+ fd.pread(maxlen, offset)
16
+ end
17
+ end
@@ -4,13 +4,10 @@
4
4
  # Test suite for the io-extra library. This test should be run via the
5
5
  # 'rake test' task.
6
6
  ###########################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'rbconfig'
12
9
  require 'io/nonblock'
13
- require 'io/extra'
10
+ require 'io-extra'
14
11
 
15
12
  class TC_IO_Extra < Test::Unit::TestCase
16
13
  def setup
@@ -20,13 +17,8 @@ class TC_IO_Extra < Test::Unit::TestCase
20
17
  end
21
18
 
22
19
  def test_version
23
- assert_equal('1.2.5', IO::EXTRA_VERSION)
24
- end
25
-
26
- def test_direct_constant
27
- omit_unless(RbConfig::CONFIG['host_os'] =~ /linux/i, 'Linux-only')
28
- assert_equal(040000, IO::DIRECT)
29
- assert_equal(040000, File::DIRECT)
20
+ assert_equal('1.4.0', IO::EXTRA_VERSION)
21
+ assert_true(IO::EXTRA_VERSION.frozen?)
30
22
  end
31
23
 
32
24
  def test_open_direct
@@ -38,20 +30,17 @@ class TC_IO_Extra < Test::Unit::TestCase
38
30
  end
39
31
 
40
32
  def test_directio
41
- omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
42
33
  assert_respond_to(@fh, :directio?)
43
34
  assert_nothing_raised{ @fh.directio? }
44
35
  end
45
36
 
46
37
  def test_directio_set
47
- omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
48
38
  assert_respond_to(@fh, :directio=)
49
39
  assert_raises(StandardError){ @fh.directio = 99 }
50
40
  assert_nothing_raised{ @fh.directio = IO::DIRECTIO_ON }
51
41
  end
52
42
 
53
43
  def test_constants
54
- omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
55
44
  assert_not_nil(IO::DIRECTIO_ON)
56
45
  assert_not_nil(IO::DIRECTIO_OFF)
57
46
  end
@@ -66,6 +55,11 @@ class TC_IO_Extra < Test::Unit::TestCase
66
55
  assert_nothing_raised{ IO.fdwalk(0){ } }
67
56
  end
68
57
 
58
+ def test_fdwalk_honors_lowfd
59
+ omit_if(RbConfig::CONFIG['host_os'] =~ /darwin/i, 'unsupported')
60
+ IO.fdwalk(1){ |f| assert_true(f.fileno >= 1) }
61
+ end
62
+
69
63
  def test_closefrom
70
64
  assert_respond_to(IO, :closefrom)
71
65
  assert_nothing_raised{ IO.closefrom(3) }
@@ -75,7 +69,7 @@ class TC_IO_Extra < Test::Unit::TestCase
75
69
  @fh.close rescue nil
76
70
  @fh = File.open(@file)
77
71
  assert_respond_to(IO, :pread)
78
- assert_equal("quick", IO.pread(@fh.fileno, 5, 4))
72
+ assert_equal("quick", IO.pread(@fh, 5, 4))
79
73
  end
80
74
 
81
75
  def test_pread_binary
@@ -86,31 +80,24 @@ class TC_IO_Extra < Test::Unit::TestCase
86
80
  assert_nothing_raised { @fh.syswrite("FOO\0HELLO") }
87
81
  @fh.close rescue nil
88
82
  @fh = File.open(@file)
89
- assert_equal("O\0H", IO.pread(@fh.fileno, 3, size + 2))
90
- end
91
-
92
- def test_pread_ptr
93
- @fh.close rescue nil
94
- @fh = File.open(@file)
95
- assert_respond_to(IO, :pread_ptr)
96
- assert_kind_of(Integer, IO.pread_ptr(@fh.fileno, 5, 4))
83
+ assert_equal("O\0H", IO.pread(@fh, 3, size + 2))
97
84
  end
98
85
 
99
86
  def test_pread_last
100
87
  @fh.close rescue nil
101
88
  @fh = File.open(@file)
102
89
  size = @fh.stat.size
103
- assert_equal("ck\n", IO.pread(@fh.fileno, 5, size - 3))
90
+ assert_equal("ck\n", IO.pread(@fh, 5, size - 3))
104
91
  end
105
92
 
106
93
  def test_pwrite
107
94
  assert_respond_to(IO, :pwrite)
108
- assert_nothing_raised{ IO.pwrite(@fh.fileno, "HAL", 0) }
95
+ assert_nothing_raised{ IO.pwrite(@fh, "HAL", 0) }
109
96
  end
110
97
 
111
98
  def test_writev
112
99
  assert_respond_to(IO, :writev)
113
- assert_equal(10, IO.writev(@fh.fileno, %w(hello world)))
100
+ assert_equal(10, IO.writev(@fh, %w[hello world]))
114
101
  end
115
102
 
116
103
  def test_writev_retry
@@ -147,9 +134,15 @@ class TC_IO_Extra < Test::Unit::TestCase
147
134
  end
148
135
  end
149
136
 
137
+ def test_ttyname
138
+ assert_respond_to(@fh, :ttyname)
139
+ assert_nil(@fh.ttyname)
140
+ assert_kind_of(String, STDOUT.ttyname)
141
+ end
142
+
150
143
  def teardown
151
144
  @fh.close rescue nil
152
145
  @fh = nil
153
- File.delete(@file) if File.exists?(@file)
146
+ File.delete(@file) if File.exist?(@file)
154
147
  end
155
148
  end
metadata CHANGED
@@ -1,97 +1,99 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: io-extra
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 5
10
- version: 1.2.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Daniel J. Berger
14
8
  autorequire:
15
9
  bindir: bin
16
- cert_chain: []
17
-
18
- date: 2011-03-23 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFAD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O+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
30
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
31
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
32
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
33
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
34
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
35
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
+ -----END CERTIFICATE-----
38
+ date:
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
22
41
  name: test-unit
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 9
30
- segments:
31
- - 2
32
- - 1
33
- - 1
34
- version: 2.1.1
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
35
47
  type: :development
36
- version_requirements: *id001
37
- description: " Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, IO.pwrite, and\n IO.writev singleton methods as well as the IO#directio and IO#directio?\n instance methods (for those platforms that support them).\n"
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ description: |2
55
+ Adds the IO.closefrom, IO.fdwalk, IO.pread, IO.pwrite, and IO.writev
56
+ singleton methods as well as the IO#directio, IO#directio? and IO#ttyname
57
+ instance methods (for those platforms that support them).
38
58
  email: djberg96@gmail.com
39
59
  executables: []
40
-
41
- extensions:
60
+ extensions:
42
61
  - ext/extconf.rb
43
- extra_rdoc_files:
62
+ extra_rdoc_files:
44
63
  - CHANGES
45
64
  - README
46
65
  - MANIFEST
47
66
  - ext/io/extra.c
48
- files:
49
- - Rakefile
50
- - README
51
- - doc/io_extra.txt
52
- - io-extra.gemspec
53
- - CHANGES
54
- - examples/example_io_extra.rb
55
- - examples/example_pread.rb
56
- - test/test_io_extra.rb
57
- - MANIFEST
58
- - ext/extconf.rb
59
- - ext/io/extra.c
60
- has_rdoc: true
61
- homepage: http://www.rubyforge.org/projects/shards
62
- licenses:
63
- - Artistic 2.0
67
+ files:
68
+ - lib/io-extra.rb
69
+ homepage: https://github.com/djberg96/io-extra
70
+ licenses:
71
+ - Apache-2.0
72
+ metadata:
73
+ homepage_uri: https://github.com/djberg96/io-extra
74
+ bug_tracker_uri: https://github.com/djberg96/io-extra/issues
75
+ changelog_uri: https://github.com/djberg96/io-extra/blob/master/CHANGES
76
+ documentation_uri: https://github.com/djberg96/io-extra/wiki
77
+ source_code_uri: https://github.com/djberg96/io-extra
78
+ wiki_uri: https://github.com/djberg96/io-extra/wiki
64
79
  post_install_message:
65
80
  rdoc_options: []
66
-
67
- require_paths:
81
+ require_paths:
68
82
  - lib
69
- required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
72
85
  - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 59
75
- segments:
76
- - 1
77
- - 8
78
- - 6
79
- version: 1.8.6
80
- required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
86
+ - !ruby/object:Gem::Version
87
+ version: 2.5.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
83
90
  - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
89
93
  requirements: []
90
-
91
- rubyforge_project: shards
92
- rubygems_version: 1.6.2
94
+ rubygems_version: 3.0.6
93
95
  signing_key:
94
- specification_version: 3
95
- summary: Adds extra methods to the IO class.
96
- test_files:
96
+ specification_version: 4
97
+ summary: Adds extra methods to the IO class
98
+ test_files:
97
99
  - test/test_io_extra.rb
Binary file
data/Rakefile DELETED
@@ -1,93 +0,0 @@
1
- require 'rake'
2
- require 'rake/clean'
3
- require 'rake/testtask'
4
- require 'rbconfig'
5
- include RbConfig
6
-
7
- CLEAN.include(
8
- '**/*.gem', # Gem files
9
- '**/*.rbc', # Rubinius
10
- '**/*.o', # C object file
11
- '**/*.log', # Ruby extension build log
12
- '**/Makefile', # C Makefile
13
- '**/conftest.dSYM', # OS X build directory
14
- "**/*.#{CONFIG['DLEXT']}" # C shared object
15
- )
16
-
17
- if File::ALT_SEPARATOR
18
- STDERR.puts 'Not supported on this platform. Exiting.'
19
- exit(-1)
20
- end
21
-
22
- desc "Build the io-extra library (but don't install it)"
23
- task :build => [:clean] do
24
- Dir.chdir('ext') do
25
- ruby 'extconf.rb'
26
- sh 'make'
27
- build_file = File.join(Dir.pwd, 'extra.' + CONFIG['DLEXT'])
28
- Dir.mkdir('io') unless File.exists?('io')
29
- FileUtils.cp(build_file, 'io')
30
- end
31
- end
32
-
33
- namespace :gem do
34
- desc 'Create the io-extra gem'
35
- task :create => [:clean] do
36
- spec = eval(IO.read('io-extra.gemspec'))
37
- Gem::Builder.new(spec).build
38
- end
39
-
40
- desc "Install the io-extra library as a gem"
41
- task :install => [:create] do
42
- file = Dir["io-extra*.gem"].last
43
- sh "gem install #{file}"
44
- end
45
- end
46
-
47
- namespace :archive do
48
- spec = eval(IO.read('io-extra.gemspec'))
49
- file = "io-extra-#{spec.version}"
50
-
51
- desc 'Create an io-extra tarball.'
52
- task :tar do
53
- file = file + ".tar"
54
- cmd = "git archive --format=tar --prefix=#{file}/ -o #{file} HEAD"
55
- sh cmd
56
- end
57
-
58
- desc 'Create a gzipped tarball for io-extra'
59
- task :gz => [:tar] do
60
- sh "gzip #{file}"
61
- end
62
-
63
- desc 'Create a bzip2 tarball for io-extra'
64
- task :bz2 => [:tar] do
65
- sh "bzip2 #{file}"
66
- end
67
-
68
- desc 'Create a zipped tarball for io-extra'
69
- task :zip do
70
- sh "git archive --format=zip --prefix=#{file}/ -o #{file}.zip HEAD"
71
- end
72
- end
73
-
74
- desc "Run the example io-extra program"
75
- task :example => [:build] do
76
- ruby '-Iext examples/example_io_extra.rb'
77
- end
78
-
79
- namespace :example do
80
- desc "Run the IO.pread example program."
81
- task :pread do
82
- ruby '-Iext examples/example_io_extra.rb'
83
- end
84
- end
85
-
86
- Rake::TestTask.new do |t|
87
- task :test => :build
88
- t.libs << 'ext'
89
- t.verbose = true
90
- t.warning = true
91
- end
92
-
93
- task :default => :test
@@ -1,85 +0,0 @@
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.