DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
file.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_FILE_FILE_H_
8 #define PACKAGER_FILE_FILE_H_
9 
10 #include <stdint.h>
11 
12 #include <string>
13 
14 #include "packager/base/macros.h"
15 
16 namespace edash_packager {
17 namespace media {
18 
19 extern const char* kLocalFilePrefix;
20 extern const char* kMemoryFilePrefix;
21 const int64_t kWholeFile = -1;
22 
24 class File {
25  public:
32  static File* Open(const char* file_name, const char* mode);
33 
40  static File* OpenWithNoBuffering(const char* file_name, const char* mode);
41 
45  static bool Delete(const char* file_name);
46 
52  virtual bool Close() = 0;
53 
60  virtual int64_t Read(void* buffer, uint64_t length) = 0;
61 
66  virtual int64_t Write(const void* buffer, uint64_t length) = 0;
67 
70  virtual int64_t Size() = 0;
71 
77  virtual bool Flush() = 0;
78 
82  virtual bool Seek(uint64_t position) = 0;
83 
88  virtual bool Tell(uint64_t* position) = 0;
89 
91  const std::string& file_name() const { return file_name_; }
92 
93  // ************************************************************
94  // * Static Methods: File-on-the-filesystem status
95  // ************************************************************
96 
99  static int64_t GetFileSize(const char* file_name);
100 
105  static bool ReadFileToString(const char* file_name, std::string* contents);
106 
113  static bool Copy(const char* from_file_name, const char* to_file_name);
114 
119  static int64_t CopyFile(File* source, File* destination);
120 
126  static int64_t CopyFile(File* source, File* destination, int64_t max_copy);
127 
128  protected:
129  explicit File(const std::string& file_name) : file_name_(file_name) {}
132  virtual ~File() {}
133 
135  virtual bool Open() = 0;
136 
137  private:
138  friend class ThreadedIoFile;
139 
140  // This is a file factory method, it creates a proper file, e.g.
141  // LocalFile, MemFile based on prefix.
142  static File* Create(const char* file_name, const char* mode);
143 
144  static File* CreateInternalFile(const char* file_name, const char* mode);
145 
146  std::string file_name_;
147  DISALLOW_COPY_AND_ASSIGN(File);
148 };
149 
150 } // namespace media
151 } // namespace edash_packager
152 
153 #endif // PACKAGER_FILE_FILE_H_
static bool ReadFileToString(const char *file_name, std::string *contents)
Definition: file.cc:184
virtual bool Seek(uint64_t position)=0
virtual int64_t Read(void *buffer, uint64_t length)=0
static bool Delete(const char *file_name)
Definition: file.cc:162
static int64_t CopyFile(File *source, File *destination)
Definition: file.cc:231
Define an abstract file interface.
Definition: file.h:24
virtual bool Open()=0
Internal open. Should not be used directly.
const std::string & file_name() const
Definition: file.h:91
virtual bool Tell(uint64_t *position)=0
virtual int64_t Size()=0
Declaration of class which implements a thread-safe circular buffer.
static bool Copy(const char *from_file_name, const char *to_file_name)
Definition: file.cc:202
virtual int64_t Write(const void *buffer, uint64_t length)=0
static int64_t GetFileSize(const char *file_name)
Definition: file.cc:175
static File * OpenWithNoBuffering(const char *file_name, const char *mode)
Definition: file.cc:151