class Tilia::Dav::Fs::File

File class

Public Instance Methods

content_type() click to toggle source

Returns the mime-type for a file

If null is returned, we'll assume application/octet-stream

@return mixed

# File lib/tilia/dav/fs/file.rb, line 63
def content_type
  nil
end
delete() click to toggle source

Delete the current file

@return void

# File lib/tilia/dav/fs/file.rb, line 34
def delete
  ::File.unlink(@path)
end
etag() click to toggle source

Returns the ETag for a file

An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. The ETag is an arbitrary string, but MUST be surrounded by double-quotes.

Return null if the ETag can not effectively be determined

@return mixed

# File lib/tilia/dav/fs/file.rb, line 53
def etag
  stat = ::File.stat(@path)
  '"' + Digest::SHA1.hexdigest(stat.ino.to_s + stat.size.to_s + stat.mtime.to_s) + '"'
end
get() click to toggle source

Returns the data

@return resource

# File lib/tilia/dav/fs/file.rb, line 27
def get
  ::File.open(@path, 'r')
end
put(data) click to toggle source

Updates the data

@param resource|string data @return void

# File lib/tilia/dav/fs/file.rb, line 14
def put(data)
  ::File.open(@path, 'w') do |file|
    if data.is_a?(String)
      file.write(data)
    else
      IO.copy_stream(data, file)
    end
  end
end
size() click to toggle source

Returns the size of the node, in bytes

@return int

# File lib/tilia/dav/fs/file.rb, line 41
def size
  ::File.size(@path)
end