Sha256: 3c82b1f6d54b6dc902aecd7f3780a28943083059c9e1f764510230b0aaf0b882

Contents?: true

Size: 862 Bytes

Versions: 16

Compression:

Stored size: 862 Bytes

Contents

require 'nodejs/file'

%x{
  function executeIOAction(action) {
    try {
      return action();
    } catch (error) {
      if (error.code === 'EACCES' ||
          error.code === 'EISDIR' ||
          error.code === 'EMFILE' ||
          error.code === 'ENOENT' ||
          error.code === 'EPERM') {
        throw Opal.IOError.$new(error.message)
      }
      throw error;
    }
  }
}

`var __fs__ = require('fs')`

class IO
  @__fs__ = `__fs__`

  attr_reader :lineno

  alias initialize_before_node_io initialize

  def initialize(fd, flags = 'r')
    @lineno = 0
    initialize_before_node_io(fd, flags)
  end

  def self.write(path, data)
    File.write(path, data)
  end

  def self.read(path)
    File.read(path)
  end

  def self.binread(path)
    `return executeIOAction(function(){return __fs__.readFileSync(#{path}).toString('binary')})`
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
opal-1.7.4 stdlib/nodejs/io.rb
opal-1.7.3 stdlib/nodejs/io.rb
opal-1.7.2 stdlib/nodejs/io.rb
opal-1.7.1 stdlib/nodejs/io.rb
opal-1.7.0 stdlib/nodejs/io.rb
opal-1.7.0.rc1 stdlib/nodejs/io.rb
opal-1.6.1 stdlib/nodejs/io.rb
opal-1.6.0 stdlib/nodejs/io.rb
opal-1.6.0.rc1 stdlib/nodejs/io.rb
opal-1.6.0.alpha1 stdlib/nodejs/io.rb
opal-1.5.1 stdlib/nodejs/io.rb
opal-1.5.0 stdlib/nodejs/io.rb
opal-1.5.0.rc1 stdlib/nodejs/io.rb
opal-1.4.1 stdlib/nodejs/io.rb
opal-1.4.0 stdlib/nodejs/io.rb
opal-1.4.0.alpha1 stdlib/nodejs/io.rb