Class: IO

Inherits:
Object
  • Object
show all
Defined in:
lib/ole/support.rb,
lib/ole/support.rb

Overview

can include File::Constants

Defined Under Namespace

Classes: Mode

Class Method Summary collapse

Class Method Details

.copy(src, dst) ⇒ Object

Copy data from IO-like object src, to dst



57
58
59
60
61
62
# File 'lib/ole/support.rb', line 57

def self.copy src, dst
	until src.eof?
		buf = src.read(4096)
		dst.write buf
	end
end

.parse_mode(mode) ⇒ Object

nabbed from rubinius, and modified



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ole/support.rb', line 170

def self.parse_mode mode
	ret = 0

	case mode[0, 1]
	when 'r'; ret |= RDONLY
	when 'w'; ret |= WRONLY | CREAT | TRUNC
	when 'a'; ret |= WRONLY | CREAT | APPEND
	else raise ArgumentError, "illegal access mode #{mode}"
	end

	(1...mode.length).each do |i|
		case mode[i, 1]
		when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR
		when 'b'; ret |= Mode::BINARY
		else raise ArgumentError, "illegal access mode #{mode}"
		end
	end

	ret
end