class Proj::FileApiImpl

Proj allows its file api to be replaced by a custom implementation. This can be done by calling Context#set_file_api with a user defined Class that includes the FileApiCallbacks module and implements its required methods.

The FileApiImpl class is a simple example file api implementation.

Public Class Methods

new(context) click to toggle source
# File lib/proj/file_api.rb, line 107
def initialize(context)
  install_callbacks(context)
end

Public Instance Methods

close() click to toggle source
# File lib/proj/file_api.rb, line 146
def close
  @file.close
end
exists(path) click to toggle source
# File lib/proj/file_api.rb, line 150
def exists(path)
  File.exist?(path)
end
mkdir(path) click to toggle source
# File lib/proj/file_api.rb, line 154
def mkdir(path)
  Dir.mkdir(path)
end
open(path, access_mode) click to toggle source
# File lib/proj/file_api.rb, line 111
def open(path, access_mode)
  case access_mode
  when :PROJ_OPEN_ACCESS_READ_ONLY
    if File.exist?(path)
      @file = File.open(path, :mode => 'rb')
    else
      nil # False
    end
  when :PROJ_OPEN_ACCESS_READ_UPDATE
    if File.exist?(path)
      @file = File.open(path, :mode => 'r+b')
    else
      nil # False
    end
  when :PROJ_OPEN_ACCESS_CREATE
    @file = File.open(path, :mode => 'wb')
  end
end
read(size_bytes) click to toggle source
# File lib/proj/file_api.rb, line 130
def read(size_bytes)
  @file.read(size_bytes)
end
rename(original_path, new_path) click to toggle source
# File lib/proj/file_api.rb, line 162
def rename(original_path, new_path)
  File.rename(original_path, new_path)
end
seek(offset, whence) click to toggle source
# File lib/proj/file_api.rb, line 138
def seek(offset, whence)
  @file.seek(offset, whence)
end
tell() click to toggle source
# File lib/proj/file_api.rb, line 142
def tell
  @file.tell
end
write(data) click to toggle source
# File lib/proj/file_api.rb, line 134
def write(data)
  @file.write(data)
end