1<?php
2
3namespace Sabre\DAV\FS;
4
5use Sabre\DAV;
6
7/**
8 * File class
9 *
10 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
11 * @author Evert Pot (http://evertpot.com/)
12 * @license http://sabre.io/license/ Modified BSD License
13 */
14class File extends Node implements DAV\IFile {
15
16    /**
17     * Updates the data
18     *
19     * @param resource $data
20     * @return void
21     */
22    function put($data) {
23
24        file_put_contents($this->path, $data);
25        clearstatcache(true, $this->path);
26
27    }
28
29    /**
30     * Returns the data
31     *
32     * @return resource
33     */
34    function get() {
35
36        return fopen($this->path, 'r');
37
38    }
39
40    /**
41     * Delete the current file
42     *
43     * @return void
44     */
45    function delete() {
46
47        unlink($this->path);
48
49    }
50
51    /**
52     * Returns the size of the node, in bytes
53     *
54     * @return int
55     */
56    function getSize() {
57
58        return filesize($this->path);
59
60    }
61
62    /**
63     * Returns the ETag for a file
64     *
65     * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
66     * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
67     *
68     * Return null if the ETag can not effectively be determined
69     *
70     * @return mixed
71     */
72    function getETag() {
73
74        return '"' . sha1(
75            fileinode($this->path) .
76            filesize($this->path) .
77            filemtime($this->path)
78        ) . '"';
79
80    }
81
82    /**
83     * Returns the mime-type for a file
84     *
85     * If null is returned, we'll assume application/octet-stream
86     *
87     * @return mixed
88     */
89    function getContentType() {
90
91        return null;
92
93    }
94
95}
96