Left: | ||
Right: |
OLD | NEW |
---|---|
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_IFILE_SYSTEM_H |
19 #define ADBLOCK_PLUS_FILE_SYSTEM_H | 19 #define ADBLOCK_PLUS_IFILE_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 #include <vector> | |
25 | 26 |
26 namespace AdblockPlus | 27 namespace AdblockPlus |
27 { | 28 { |
28 /** | 29 /** |
29 * File system interface. | 30 * File system interface. |
30 */ | 31 */ |
31 class FileSystem | 32 class IFileSystem |
32 { | 33 { |
33 public: | 34 public: |
34 /** | 35 /** |
35 * Result of a stat operation, i.e.\ information about a file. | 36 * Result of a stat operation, i.e.\ information about a file. |
36 */ | 37 */ |
37 struct StatResult | 38 struct StatResult |
38 { | 39 { |
39 StatResult() | 40 StatResult() |
40 { | 41 { |
41 exists = false; | 42 exists = false; |
(...skipping 16 matching lines...) Expand all Loading... | |
58 * File is a regular file. | 59 * File is a regular file. |
59 */ | 60 */ |
60 bool isFile; | 61 bool isFile; |
61 | 62 |
62 /** | 63 /** |
63 * POSIX time of the last modification. | 64 * POSIX time of the last modification. |
64 */ | 65 */ |
65 int64_t lastModified; | 66 int64_t lastModified; |
66 }; | 67 }; |
67 | 68 |
68 virtual ~FileSystem() {} | 69 virtual ~IFileSystem() {} |
70 | |
71 /** | |
72 * Default callback type for asynchronous filesystem calls. | |
73 * @param An error string. Empty is success. | |
74 */ | |
75 typedef std::function<void(const std::string&)> Callback; | |
76 | |
77 /** | |
78 * Callback type for the asynchronous Read call. | |
79 * @param Output char array with file content. | |
80 * @param An error string. Empty if success. | |
81 */ | |
82 typedef std::function<void(std::vector<char>&&, | |
sergei
2017/07/06 14:14:05
Since it's for bytes, I would rather prefer an uns
hub
2017/07/06 14:33:31
But iostream and making it harder. If I use std::v
sergei
2017/07/06 14:53:33
I think we should simply cast to `const char*` or
hub
2017/07/06 21:24:30
fair enough.
| |
83 const std::string&)> ReadCallback; | |
69 | 84 |
70 /** | 85 /** |
71 * Reads from a file. | 86 * Reads from a file. |
72 * @param path File path. | 87 * @param path File path. |
73 * @return Input stream with the file's contents. | 88 * @param callback The function called on completion with the input data. |
74 */ | 89 */ |
75 virtual std::shared_ptr<std::istream> | 90 virtual void Read(const std::string& path, |
76 Read(const std::string& path) const = 0; | 91 const ReadCallback& callback) const = 0; |
77 | 92 |
78 /** | 93 /** |
79 * Writes to a file. | 94 * Writes to a file. |
80 * @param path File path. | 95 * @param path File path. |
81 * @param data Input stream with the data to write. | 96 * @param data The data to write. |
97 * @param callback The function called on completion. | |
82 */ | 98 */ |
83 virtual void Write(const std::string& path, | 99 virtual void Write(const std::string& path, |
84 std::istream& data) = 0; | 100 const std::vector<char>& data, |
101 const Callback& callback) = 0; | |
85 | 102 |
86 /** | 103 /** |
87 * Moves a file (i.e.\ renames it). | 104 * Moves a file (i.e.\ renames it). |
88 * @param fromPath Current path to the file. | 105 * @param fromPath Current path to the file. |
89 * @param toPath New path to the file. | 106 * @param toPath New path to the file. |
107 * @param callback The function called on completion. | |
90 */ | 108 */ |
91 virtual void Move(const std::string& fromPath, | 109 virtual void Move(const std::string& fromPath, const std::string& toPath, |
92 const std::string& toPath) = 0; | 110 const Callback& callback) = 0; |
93 | 111 |
94 /** | 112 /** |
95 * Removes a file. | 113 * Removes a file. |
96 * @param path File path. | 114 * @param path File path. |
115 * @param callback The function called on completion. | |
97 */ | 116 */ |
98 virtual void Remove(const std::string& path) = 0; | 117 virtual void Remove(const std::string& path, const Callback& callback) = 0; |
118 | |
119 /** | |
120 * Callback type for the asynchronous Stat call. | |
121 * @param the StatResult data. | |
122 * @param an error string. Empty if no error. | |
123 */ | |
124 typedef std::function<void(const StatResult&, const std::string&)> StatCallb ack; | |
99 | 125 |
100 /** | 126 /** |
101 * Retrieves information about a file. | 127 * Retrieves information about a file. |
102 * @param path File path. | 128 * @param path File path. |
103 * @return File information. | 129 * @param callback The function called on completion. |
104 */ | 130 */ |
105 virtual StatResult Stat(const std::string& path) const = 0; | 131 virtual void Stat(const std::string& path, |
132 const StatCallback& callback) const = 0; | |
106 | 133 |
107 /** | 134 /** |
108 * Returns the absolute path to a file. | 135 * Returns the absolute path to a file. |
109 * @param path File path (can be relative or absolute). | 136 * @param path File path (can be relative or absolute). |
110 * @return Absolute file path. | 137 * @return Absolute file path. |
111 */ | 138 */ |
112 virtual std::string Resolve(const std::string& path) const = 0; | 139 virtual std::string Resolve(const std::string& path) const = 0; |
113 }; | 140 }; |
114 | 141 |
115 /** | 142 /** |
116 * Shared smart pointer to a `FileSystem` instance. | 143 * Shared smart pointer to a `IFileSystem` instance. |
117 */ | 144 */ |
118 typedef std::shared_ptr<FileSystem> FileSystemPtr; | 145 typedef std::shared_ptr<IFileSystem> FileSystemPtr; |
119 } | 146 } |
120 | 147 |
121 #endif | 148 #endif |
OLD | NEW |