Class: Tus::Storage::Filesystem
- Inherits:
-
Object
- Object
- Tus::Storage::Filesystem
- Defined in:
- lib/tus/storage/filesystem.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
- #create_file(uid, info = {}) ⇒ Object
- #delete_file(uid) ⇒ Object
- #download_file(uid) ⇒ Object
- #file_exists?(uid) ⇒ Boolean
-
#initialize(directory) ⇒ Filesystem
constructor
A new instance of Filesystem.
- #list_files ⇒ Object
- #patch_file(uid, content) ⇒ Object
- #read_file(uid) ⇒ Object
- #read_info(uid) ⇒ Object
- #update_info(uid, info) ⇒ Object
Constructor Details
#initialize(directory) ⇒ Filesystem
Returns a new instance of Filesystem.
9 10 11 12 13 |
# File 'lib/tus/storage/filesystem.rb', line 9 def initialize(directory) @directory = Pathname(directory) create_directory! unless @directory.exist? end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
7 8 9 |
# File 'lib/tus/storage/filesystem.rb', line 7 def directory @directory end |
Instance Method Details
#create_file(uid, info = {}) ⇒ Object
15 16 17 18 |
# File 'lib/tus/storage/filesystem.rb', line 15 def create_file(uid, info = {}) write(file_path(uid), "") write(info_path(uid), info.to_json) end |
#delete_file(uid) ⇒ Object
36 37 38 39 |
# File 'lib/tus/storage/filesystem.rb', line 36 def delete_file(uid) file_path(uid).delete info_path(uid).delete end |
#download_file(uid) ⇒ Object
32 33 34 |
# File 'lib/tus/storage/filesystem.rb', line 32 def download_file(uid) file_path(uid).to_s end |
#file_exists?(uid) ⇒ Boolean
20 21 22 |
# File 'lib/tus/storage/filesystem.rb', line 20 def file_exists?(uid) file_path(uid).exist? && info_path(uid).exist? end |
#list_files ⇒ Object
50 51 52 53 |
# File 'lib/tus/storage/filesystem.rb', line 50 def list_files paths = Dir[directory.join("*.file")] paths.map { |path| File.basename(path, ".file") } end |
#patch_file(uid, content) ⇒ Object
28 29 30 |
# File 'lib/tus/storage/filesystem.rb', line 28 def patch_file(uid, content) write(file_path(uid), content, mode: "ab") end |
#read_file(uid) ⇒ Object
24 25 26 |
# File 'lib/tus/storage/filesystem.rb', line 24 def read_file(uid) file_path(uid).binread end |
#read_info(uid) ⇒ Object
41 42 43 44 |
# File 'lib/tus/storage/filesystem.rb', line 41 def read_info(uid) data = info_path(uid).binread JSON.parse(data) end |
#update_info(uid, info) ⇒ Object
46 47 48 |
# File 'lib/tus/storage/filesystem.rb', line 46 def update_info(uid, info) write(info_path(uid), info.to_json) end |