7 #include "packager/media/file/memory_file.h"
13 #include "packager/base/logging.h"
14 #include "packager/base/memory/scoped_ptr.h"
16 namespace edash_packager {
25 static FileSystem* Instance() {
27 g_file_system_.reset(
new FileSystem());
29 return g_file_system_.get();
32 std::vector<uint8_t>* GetFile(
const std::string& file_name) {
33 return &files_[file_name];
36 void Delete(
const std::string& file_name) { files_.erase(file_name); }
38 void DeleteAll() { files_.clear(); }
43 static scoped_ptr<FileSystem> g_file_system_;
45 std::map<std::string, std::vector<uint8_t> > files_;
46 DISALLOW_COPY_AND_ASSIGN(FileSystem);
49 scoped_ptr<FileSystem> FileSystem::g_file_system_;
53 MemoryFile::MemoryFile(
const std::string& file_name)
55 file_(FileSystem::Instance()->GetFile(file_name)),
58 MemoryFile::~MemoryFile() {}
66 const uint64_t size =
Size();
67 DCHECK_LE(position_, size);
68 if (position_ >= size)
71 const uint64_t bytes_to_read = std::min(length, size - position_);
72 memcpy(buffer, &(*file_)[position_], bytes_to_read);
73 position_ += bytes_to_read;
78 const uint64_t size =
Size();
79 if (size < position_ + length) {
80 file_->resize(position_ + length);
83 memcpy(&(*file_)[position_], buffer, length);
97 if (
Size() < static_cast<int64_t>(position))
100 position_ = position;
105 *position = position_;
115 FileSystem::Instance()->DeleteAll();
119 FileSystem::Instance()->Delete(file_name);