userver: userver/fs/read.hpp Source File
Loading...
Searching...
No Matches
read.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/fs/read.hpp
4/// @brief functions for asynchronous file read operations
5
6#include <cstddef>
7#include <limits>
8#include <string>
9
10#include <userver/engine/task/task_processor_fwd.hpp>
11#include <userver/fs/file_info_with_data.hpp>
12#include <userver/fs/path_utils.hpp>
13#include <userver/fs/settings_read_file.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17/// @brief filesystem support
18namespace fs {
19
20/// @brief Returns files from recursively traversed directory
21/// @param async_tp TaskProcessor for synchronous waiting
22/// @param path to directory to traverse recursively
23/// @param flags settings read files
24/// @param max_size_to_cache files larger than this store a full path in
25/// @ref FileInfoWithData::data_or_path instead of contents
26/// @returns map with relative to `path` filepaths and file info
27/// @throws std::runtime_error if read fails for any reason (e.g. no such file, read error, etc.),
29 engine::TaskProcessor& async_tp,
30 const std::string& path,
31 SettingReadFileFlags flags = {SettingsReadFile::kSkipHidden},
32 std::size_t max_size_to_cache = std::numeric_limits<std::size_t>::max()
33);
34
35/// @brief Reads file contents asynchronously
36/// @param async_tp TaskProcessor for synchronous waiting
37/// @param path file to open
38/// @returns file contents
39/// @throws std::runtime_error if read fails for any reason (e.g. no such file, read error, etc.),
40std::string ReadFileContents(engine::TaskProcessor& async_tp, const std::string& path);
41
42/// @brief Checks whether the file exists asynchronously
43/// @param async_tp TaskProcessor for synchronous waiting
44/// @param path file path to check
45/// @returns true if file exists, false if file doesn't exist
46/// @throws std::runtime_error if something goes wrong (e.g. out of file descriptors)
47bool FileExists(engine::TaskProcessor& async_tp, const std::string& path);
48
49} // namespace fs
50
51USERVER_NAMESPACE_END