Class: Defile::File
- Inherits:
-
Object
- Object
- Defile::File
- Defined in:
- lib/defile/file.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #close ⇒ Object
- #delete ⇒ Object
- #download ⇒ Object
- #each ⇒ Object
- #eof? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(backend, id) ⇒ File
constructor
A new instance of File.
- #read(*args) ⇒ Object
- #size ⇒ Object
- #to_io ⇒ Object
Constructor Details
#initialize(backend, id) ⇒ File
Returns a new instance of File.
5 6 7 8 |
# File 'lib/defile/file.rb', line 5 def initialize(backend, id) @backend = backend @id = id end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
3 4 5 |
# File 'lib/defile/file.rb', line 3 def backend @backend end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/defile/file.rb', line 3 def id @id end |
Instance Method Details
#close ⇒ Object
18 19 20 |
# File 'lib/defile/file.rb', line 18 def close io.close end |
#delete ⇒ Object
26 27 28 |
# File 'lib/defile/file.rb', line 26 def delete backend.delete(id) end |
#download ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/defile/file.rb', line 38 def download tempfile = Tempfile.new(id) tempfile.binmode each do |chunk| tempfile.write(chunk) end close tempfile.close tempfile end |
#each ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/defile/file.rb', line 49 def each if block_given? until eof? yield(read(Defile.read_chunk_size)) end else to_enum end end |
#eof? ⇒ Boolean
14 15 16 |
# File 'lib/defile/file.rb', line 14 def eof? io.eof? end |
#exists? ⇒ Boolean
30 31 32 |
# File 'lib/defile/file.rb', line 30 def exists? backend.exists?(id) end |
#read(*args) ⇒ Object
10 11 12 |
# File 'lib/defile/file.rb', line 10 def read(*args) io.read(*args) end |
#size ⇒ Object
22 23 24 |
# File 'lib/defile/file.rb', line 22 def size backend.size(id) end |
#to_io ⇒ Object
34 35 36 |
# File 'lib/defile/file.rb', line 34 def to_io io end |