1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
This commit is contained in:
David Heinemeier Hansson 2017-07-01 12:05:58 +02:00
parent 97b2978d70
commit fcdbaf7e61

View file

@ -20,22 +20,26 @@ class ActiveFile::Sites::DiskSite < ActiveFile::Site
def download(key)
if block_given?
open(path_for(key)) do |file|
File.open(path_for(key)) do |file|
while data = file.read(65536)
yield data
end
end
else
open(path_for(key), &:read)
File.open path_for(key), &:read
end
end
def delete(key)
File.delete(path_for(key))
File.delete path_for(key)
end
def exists?(key)
File.exist? path_for(key)
end
def size(key)
File.size(path_for(key))
File.size path_for(key)
end
def checksum(key)
@ -44,11 +48,11 @@ class ActiveFile::Sites::DiskSite < ActiveFile::Site
private
def path_for(key)
File.join(root, folder_for(key), key)
File.join root, folder_for(key), key
end
def folder_for(key)
[key[0..1], key[2..3]].join("/")
[ key[0..1], key[2..3] ].join("/")
end
def make_path_for(key)