Class: Defile::File

Inherits:
Object
  • Object
show all
Defined in:
lib/defile/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backendObject (readonly)

Returns the value of attribute backend.



3
4
5
# File 'lib/defile/file.rb', line 3

def backend
  @backend
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/defile/file.rb', line 3

def id
  @id
end

Instance Method Details

#closeObject



18
19
20
# File 'lib/defile/file.rb', line 18

def close
  io.close
end

#deleteObject



26
27
28
# File 'lib/defile/file.rb', line 26

def delete
  backend.delete(id)
end

#downloadObject



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

#eachObject



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

Returns:

  • (Boolean)


14
15
16
# File 'lib/defile/file.rb', line 14

def eof?
  io.eof?
end

#exists?Boolean

Returns:

  • (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

#sizeObject



22
23
24
# File 'lib/defile/file.rb', line 22

def size
  backend.size(id)
end

#to_ioObject



34
35
36
# File 'lib/defile/file.rb', line 34

def to_io
  io
end