Class: QuartzTorrent::IOManager

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_torrent/filemanager.rb

Overview

Basic IOManager that isn’t used by a reactor.

Instance Method Summary collapse

Constructor Details

#initializeIOManager

Returns a new instance of IOManager.



116
117
118
# File 'lib/quartz_torrent/filemanager.rb', line 116

def initialize
  @io = {}
end

Instance Method Details

#flushObject



137
138
139
140
141
# File 'lib/quartz_torrent/filemanager.rb', line 137

def flush
  @io.each do |k,v|
    v.flush
  end
end

#get(path) ⇒ Object



120
121
122
# File 'lib/quartz_torrent/filemanager.rb', line 120

def get(path)
  @io[path]
end

#open(path) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/quartz_torrent/filemanager.rb', line 124

def open(path)
  # Open the file for read/write.
  # If the file exists, open as r+ so it is not truncated.
  # Otherwise open as w+
  if File.exists?(path)
    io = File.open(path, "rb+")
  else
    io = File.open(path, "wb+")
  end
  @io[path] = io
  io
end