Class: File

Inherits:
Object show all
Defined in:
lib/sane.rb

Overview

require ‘facets/file’ ===>

Class Method Summary collapse

Class Method Details

.binread(path) ⇒ Object



20
21
22
23
24
# File 'lib/sane.rb', line 20

def self.binread(path)
  File.open(path, "rb") do |file|
    return file.read
  end
end

.binwrite(path, data) ⇒ Object



26
27
28
29
30
# File 'lib/sane.rb', line 26

def self.binwrite(path, data)
  File.open(path, "wb") do |file|
    return file.write(data)
  end
end

.write(path, data) ⇒ Object

Writes the given data to the given path and closes the file. This is done in binary mode, complementing IO.read in standard Ruby.

Returns the number of bytes written.

CREDIT: facets/Gavin Sinclair



14
15
16
17
18
# File 'lib/sane.rb', line 14

def self.write(path, data)
  File.open(path, "w") do |file|
    return file.write(data)
  end
end