DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs 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 const int64_t kWholeFile = -1;
21 
23 class File {
24  public:
31  static File* Open(const char* file_name, const char* mode);
32 
39  static File* OpenWithNoBuffering(const char* file_name, const char* mode);
40 
44  static bool Delete(const char* file_name);
45 
51  virtual bool Close() = 0;
52 
59  virtual int64_t Read(void* buffer, uint64_t length) = 0;
60 
65  virtual int64_t Write(const void* buffer, uint64_t length) = 0;
66 
69  virtual int64_t Size() = 0;
70 
76  virtual bool Flush() = 0;
77 
81  virtual bool Seek(uint64_t position) = 0;
82 
87  virtual bool Tell(uint64_t* position) = 0;
88 
90  const std::string& file_name() const { return file_name_; }
91 
92  // ************************************************************
93  // * Static Methods: File-on-the-filesystem status
94  // ************************************************************
95 
98  static int64_t GetFileSize(const char* file_name);
99 
104  static bool ReadFileToString(const char* file_name, std::string* contents);
105 
112  static bool Copy(const char* from_file_name, const char* to_file_name);
113 
118  static int64_t CopyFile(File* source, File* destination);
119 
125  static int64_t CopyFile(File* source, File* destination, int64_t max_copy);
126 
127  protected:
128  explicit File(const std::string& file_name) : file_name_(file_name) {}
131  virtual ~File() {}
132 
134  virtual bool Open() = 0;
135 
136  private:
137  friend class ThreadedIoFile;
138 
139  // This is a file factory method, it creates a proper file, e.g.
140  // LocalFile, MemFile based on prefix.
141  static File* Create(const char* file_name, const char* mode);
142 
143  static File* CreateInternalFile(const char* file_name, const char* mode);
144 
145  std::string file_name_;
146  DISALLOW_COPY_AND_ASSIGN(File);
147 };
148 
149 } // namespace media
150 } // namespace edash_packager
151 
152 #endif // PACKAGER_FILE_FILE_H_
static bool ReadFileToString(const char *file_name, std::string *contents)
Definition: file.cc:162
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:140
static int64_t CopyFile(File *source, File *destination)
Definition: file.cc:210
Define an abstract file interface.
Definition: file.h:23
virtual bool Open()=0
Internal open. Should not be used directly.
const std::string & file_name() const
Definition: file.h:90
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:180
virtual int64_t Write(const void *buffer, uint64_t length)=0
static int64_t GetFileSize(const char *file_name)
Definition: file.cc:153
static File * OpenWithNoBuffering(const char *file_name, const char *mode)
Definition: file.cc:129