file_util.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the LICENSE file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. #ifndef LIBWEBM_COMMON_FILE_UTIL_H_
  9. #define LIBWEBM_COMMON_FILE_UTIL_H_
  10. #include <stdint.h>
  11. #include <string>
  12. #include "mkvmuxer/mkvmuxertypes.h" // LIBWEBM_DISALLOW_COPY_AND_ASSIGN()
  13. namespace libwebm {
  14. // Returns a temporary file name.
  15. std::string GetTempFileName();
  16. // Returns size of file specified by |file_name|, or 0 upon failure.
  17. uint64_t GetFileSize(const std::string& file_name);
  18. // Gets the contents file_name as a string. Returns false on error.
  19. bool GetFileContents(const std::string& file_name, std::string* contents);
  20. // Manages life of temporary file specified at time of construction. Deletes
  21. // file upon destruction.
  22. class TempFileDeleter {
  23. public:
  24. TempFileDeleter();
  25. explicit TempFileDeleter(std::string file_name) : file_name_(file_name) {}
  26. ~TempFileDeleter();
  27. const std::string& name() const { return file_name_; }
  28. private:
  29. std::string file_name_;
  30. LIBWEBM_DISALLOW_COPY_AND_ASSIGN(TempFileDeleter);
  31. };
  32. } // namespace libwebm
  33. #endif // LIBWEBM_COMMON_FILE_UTIL_H_