Class: Fog::Storage::Local::Files

Inherits:
Collection
  • Object
show all
Defined in:
lib/right_publish/stores/local.rb

Instance Method Summary collapse

Instance Method Details

#get(key, &block) ⇒ Object

This method is exactly like the stock one except for using “rb” (force binary mode) instead of “r” for reading the file. On windows it defaults to text mode which messes everything up.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/right_publish/stores/local.rb', line 13

def get(key, &block)
  requires :directory
  path = file_path(key)
  if ::File.exists?(path)
    data = {
      :content_length => ::File.size(path),
      :key            => key,
      :last_modified  => ::File.mtime(path)
    }
    if block_given?
      file = ::File.open(path, "rb")
      while (chunk = file.read(Excon::CHUNK_SIZE)) && yield(chunk); end
      file.close
      new(data)
    else
      body = ::File.open(path,"rb") { |io| io.read }
      new(data.merge!(:body => body))
    end
  else
    nil
  end
end