1 #ifndef IMAGE_IO_UTILS_FILE_UTILS_H_  // NOLINT
2 #define IMAGE_IO_UTILS_FILE_UTILS_H_  // NOLINT
3 
4 #include <iostream>
5 #include <memory>
6 #include <string>
7 
8 #include "image_io/base/data_segment.h"
9 #include "image_io/base/message_handler.h"
10 
11 namespace photos_editing_formats {
12 namespace image_io {
13 
14 /// @param file_name The name of the file to get the size in bytes of.
15 /// @param size A pointer to a variable to receive the size.
16 /// @return Whether file size was obtained properly.
17 bool GetFileSize(const std::string& file_name, size_t* size);
18 
19 /// @param file_name The name of the file to open for output.
20 /// @param message_handler Optional message handler to write messages to.
21 /// @return An ostream pointer or nullptr if the open failed.
22 std::unique_ptr<std::ostream> OpenOutputFile(const std::string& file_name,
23                                              MessageHandler* message_handler);
24 
25 /// @param file_name The name of the file to open for input.
26 /// @param message_handler Optional message handler to write messages to.
27 /// @return An istream pointer or nullptr if the open failed.
28 std::unique_ptr<std::istream> OpenInputFile(const std::string& file_name,
29                                             MessageHandler* message_handler);
30 
31 /// Opens the named file for input, gets its size, and reads the entire contents
32 /// into a data segment that is returned to the caller.
33 /// @param file_name The name of the file to open for input.
34 /// @param message_handler Optional message handler to write messages to.
35 /// @return A DataSegment pointer or nullptr if the open and reading failed.
36 std::shared_ptr<DataSegment> ReadEntireFile(const std::string& file_name,
37                                             MessageHandler* message_handler);
38 
39 }  // namespace image_io
40 }  // namespace photos_editing_formats
41 
42 #endif // IMAGE_IO_UTILS_FILE_UTILS_H_  // NOLINT
43