Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #ifndef ADBLOCK_PLUS_FILE_SYSTEM_H | 18 #ifndef ADBLOCK_PLUS_FILE_SYSTEM_H |
19 #define ADBLOCK_PLUS_FILE_SYSTEM_H | 19 #define ADBLOCK_PLUS_FILE_SYSTEM_H |
20 | 20 |
21 #include <istream> | 21 #include <istream> |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 #include <string> | 23 #include <string> |
24 #include <memory> | 24 #include <memory> |
25 | 25 |
26 #include "IFileSystem.h" | |
27 | |
26 namespace AdblockPlus | 28 namespace AdblockPlus |
27 { | 29 { |
28 /** | 30 /** |
29 * File system interface. | 31 * File system interface. |
30 */ | 32 */ |
31 class FileSystem | 33 class FileSystem |
sergei
2017/05/26 13:32:04
I expected to have a completely new interface with
| |
32 { | 34 { |
33 public: | 35 public: |
34 /** | |
35 * Result of a stat operation, i.e.\ information about a file. | |
36 */ | |
37 struct StatResult | |
38 { | |
39 StatResult() | |
40 { | |
41 exists = false; | |
42 isDirectory = false; | |
43 isFile = false; | |
44 lastModified = 0; | |
45 } | |
46 | |
47 /** | |
48 * File exists. | |
49 */ | |
50 bool exists; | |
51 | |
52 /** | |
53 * File is a directory. | |
54 */ | |
55 bool isDirectory; | |
56 | |
57 /** | |
58 * File is a regular file. | |
59 */ | |
60 bool isFile; | |
61 | |
62 /** | |
63 * POSIX time of the last modification. | |
64 */ | |
65 int64_t lastModified; | |
66 }; | |
67 | |
68 virtual ~FileSystem() {} | 36 virtual ~FileSystem() {} |
69 | |
70 typedef std::function<void (void)> Callback; | |
sergei
2017/05/26 13:32:04
Not sure whether we use a space between return typ
sergei
2017/05/26 13:32:04
We need a documentation for public things.
sergei
2017/05/26 13:32:04
Could you please not use (void), it's equivalent t
hub
2017/06/02 16:04:16
I would put a space, but then elsewhere it doesn't
hub
2017/06/02 16:04:16
Acknowledged.
| |
71 typedef std::function<void (std::shared_ptr<std::istream>)> ReadCallback; | |
sergei
2017/05/26 13:32:04
I would propose to change the signature to
std::fu
| |
72 | 37 |
73 /** | 38 /** |
74 * Reads from a file. | 39 * Reads from a file. |
75 * @param path File path. | 40 * @param path File path. |
76 * @return Input stream with the file's contents. | 41 * @return Buffer with the file content. |
77 */ | 42 */ |
78 virtual std::shared_ptr<std::istream> | 43 virtual IFileSystem::IOBuffer Read(const std::string& path) const = 0; |
79 Read(const std::string& path) const = 0; | |
80 virtual void Read(const std::string& path, | |
81 const ReadCallback& callback) const = 0; | |
82 | 44 |
83 /** | 45 /** |
84 * Writes to a file. | 46 * Writes to a file. |
85 * @param path File path. | 47 * @param path File path. |
86 * @param data Input stream with the data to write. | 48 * @param data Buffer with the data to write. |
87 */ | 49 */ |
88 virtual void Write(const std::string& path, | 50 virtual void Write(const std::string& path, |
89 std::istream& data) = 0; | 51 const IFileSystem::IOBuffer& data) = 0; |
90 virtual void Write(const std::string& path, | |
91 std::istream& data, | |
92 const Callback& callback) = 0; | |
93 | 52 |
94 /** | 53 /** |
95 * Moves a file (i.e.\ renames it). | 54 * Moves a file (i.e.\ renames it). |
96 * @param fromPath Current path to the file. | 55 * @param fromPath Current path to the file. |
97 * @param toPath New path to the file. | 56 * @param toPath New path to the file. |
98 */ | 57 */ |
99 virtual void Move(const std::string& fromPath, | 58 virtual void Move(const std::string& fromPath, |
100 const std::string& toPath) = 0; | 59 const std::string& toPath) = 0; |
101 virtual void Move(const std::string& fromPath, | |
102 const std::string& toPath, | |
103 const Callback& callback) = 0; | |
104 | 60 |
105 /** | 61 /** |
106 * Removes a file. | 62 * Removes a file. |
107 * @param path File path. | 63 * @param path File path. |
108 */ | 64 */ |
109 virtual void Remove(const std::string& path) = 0; | 65 virtual void Remove(const std::string& path) = 0; |
110 virtual void Remove(const std::string& path, const Callback& callback) = 0; | |
111 | 66 |
112 typedef std::function<void (const StatResult&)> StatCallback; | |
113 /** | 67 /** |
114 * Retrieves information about a file. | 68 * Retrieves information about a file. |
115 * @param path File path. | 69 * @param path File path. |
116 * @return File information. | 70 * @return File information. |
117 */ | 71 */ |
118 virtual StatResult Stat(const std::string& path) const = 0; | 72 virtual IFileSystem::StatResult Stat(const std::string& path) const = 0; |
119 virtual void Stat(const std::string& path, | |
120 const StatCallback& callback) const = 0; | |
121 | 73 |
122 typedef std::function<void (const std::string&)> ResolveCallback; | |
123 /** | 74 /** |
124 * Returns the absolute path to a file. | 75 * Returns the absolute path to a file. |
125 * @param path File path (can be relative or absolute). | 76 * @param path File path (can be relative or absolute). |
126 * @return Absolute file path. | 77 * @return Absolute file path. |
127 */ | 78 */ |
128 virtual std::string Resolve(const std::string& path) const = 0; | 79 virtual std::string Resolve(const std::string& path) const = 0; |
129 virtual void Resolve(const std::string& path, | |
sergei
2017/05/26 13:32:04
I'm not sure whether resolve should be asynchronou
hub
2017/06/02 16:04:16
I thought twice about that. I looked at NodeJS for
| |
130 const ResolveCallback& callback) const = 0; | |
131 }; | 80 }; |
132 | 81 |
133 /** | 82 /** |
134 * Shared smart pointer to a `FileSystem` instance. | 83 * Shared smart pointer to a `FileSystem` instance. |
135 */ | 84 */ |
136 typedef std::shared_ptr<FileSystem> FileSystemPtr; | 85 typedef std::shared_ptr<FileSystem> FileSystemSyncPtr; |
137 } | 86 } |
138 | 87 |
139 #endif | 88 #endif |
LEFT | RIGHT |