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