Class: IO
Instance Attribute Summary collapse
-
#eof ⇒ Object
readonly
Returns the value of attribute eof.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Class Method Summary collapse
Instance Method Summary collapse
- #each_line(separator = $/, &block) ⇒ Object
-
#initialize ⇒ IO
constructor
A new instance of IO.
- #read ⇒ Object
Constructor Details
#initialize ⇒ IO
Returns a new instance of IO
26 27 28 29 |
# File 'opal/stdlib/nodejs/io.rb', line 26 def initialize @eof = false @lineno = 0 end |
Instance Attribute Details
#eof ⇒ Object (readonly)
Returns the value of attribute eof
23 24 25 |
# File 'opal/stdlib/nodejs/io.rb', line 23 def eof @eof end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno
24 25 26 |
# File 'opal/stdlib/nodejs/io.rb', line 24 def lineno @lineno end |
Class Method Details
.binread(path) ⇒ Object
80 81 82 |
# File 'opal/stdlib/nodejs/io.rb', line 80 def self.binread(path) `return executeIOAction(function(){return __fs__.readFileSync(#{path}).toString('binary')})` end |
Instance Method Details
#each_line(separator = $/, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'opal/stdlib/nodejs/io.rb', line 50 def each_line(separator = $/, &block) if @eof return block_given? ? self : [].to_enum end if block_given? lines = File.read(@path) %x{ self.eof = false; self.lineno = 0; var chomped = #{lines.chomp}, trailing = lines.length != chomped.length, splitted = chomped.split(separator); for (var i = 0, length = splitted.length; i < length; i++) { self.lineno += 1; if (i < length - 1 || trailing) { #{yield `splitted[i] + separator`}; } else { #{yield `splitted[i]`}; } } self.eof = true; } self else read.each_line end end |
#read ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'opal/stdlib/nodejs/io.rb', line 39 def read if @eof '' else res = `executeIOAction(function(){return __fs__.readFileSync(#{@path}).toString()})` @eof = true @lineno = res.size res end end |