aboutsummaryrefslogtreecommitdiff
path: root/third_party/image_io/includes/image_io/utils/file_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/image_io/includes/image_io/utils/file_utils.h')
-rw-r--r--third_party/image_io/includes/image_io/utils/file_utils.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/third_party/image_io/includes/image_io/utils/file_utils.h b/third_party/image_io/includes/image_io/utils/file_utils.h
new file mode 100644
index 0000000..3a8d2c6
--- /dev/null
+++ b/third_party/image_io/includes/image_io/utils/file_utils.h
@@ -0,0 +1,42 @@
+#ifndef IMAGE_IO_UTILS_FILE_UTILS_H_ // NOLINT
+#define IMAGE_IO_UTILS_FILE_UTILS_H_ // NOLINT
+
+#include <iostream>
+#include <memory>
+#include <string>
+
+#include "image_io/base/data_segment.h"
+#include "image_io/base/message_handler.h"
+
+namespace photos_editing_formats {
+namespace image_io {
+
+/// @param file_name The name of the file to get the size in bytes of.
+/// @param size A pointer to a variable to receive the size.
+/// @return Whether file size was obtained properly.
+bool GetFileSize(const std::string& file_name, size_t* size);
+
+/// @param file_name The name of the file to open for output.
+/// @param message_handler Optional message handler to write messages to.
+/// @return An ostream pointer or nullptr if the open failed.
+std::unique_ptr<std::ostream> OpenOutputFile(const std::string& file_name,
+ MessageHandler* message_handler);
+
+/// @param file_name The name of the file to open for input.
+/// @param message_handler Optional message handler to write messages to.
+/// @return An istream pointer or nullptr if the open failed.
+std::unique_ptr<std::istream> OpenInputFile(const std::string& file_name,
+ MessageHandler* message_handler);
+
+/// Opens the named file for input, gets its size, and reads the entire contents
+/// into a data segment that is returned to the caller.
+/// @param file_name The name of the file to open for input.
+/// @param message_handler Optional message handler to write messages to.
+/// @return A DataSegment pointer or nullptr if the open and reading failed.
+std::shared_ptr<DataSegment> ReadEntireFile(const std::string& file_name,
+ MessageHandler* message_handler);
+
+} // namespace image_io
+} // namespace photos_editing_formats
+
+#endif // IMAGE_IO_UTILS_FILE_UTILS_H_ // NOLINT