2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2015 Google LLC. All rights reserved.
|
2015-12-22 00:20:34 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#ifndef MEDIA_FILE_MEDIA_FILE_H_
|
|
|
|
#define MEDIA_FILE_MEDIA_FILE_H_
|
|
|
|
|
2023-10-11 08:49:50 +00:00
|
|
|
#include <cstdint>
|
2015-12-22 00:20:34 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/file/file.h>
|
2015-12-22 00:20:34 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-12-22 00:20:34 +00:00
|
|
|
|
|
|
|
/// Implements a File that is stored in memory. This should be only used for
|
|
|
|
/// testing, since this does not support larger files.
|
|
|
|
class MemoryFile : public File {
|
|
|
|
public:
|
2015-12-22 00:33:55 +00:00
|
|
|
MemoryFile(const std::string& file_name, const std::string& mode);
|
2015-12-22 00:20:34 +00:00
|
|
|
|
|
|
|
/// @name File implementation overrides.
|
|
|
|
/// @{
|
|
|
|
bool Close() override;
|
|
|
|
int64_t Read(void* buffer, uint64_t length) override;
|
|
|
|
int64_t Write(const void* buffer, uint64_t length) override;
|
2023-07-14 01:55:48 +00:00
|
|
|
void CloseForWriting() override;
|
2015-12-22 00:20:34 +00:00
|
|
|
int64_t Size() override;
|
|
|
|
bool Flush() override;
|
|
|
|
bool Seek(uint64_t position) override;
|
|
|
|
bool Tell(uint64_t* position) override;
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// Deletes all memory file data created. This assumes that there are no
|
|
|
|
/// MemoryFile objects alive. Any alive objects will be in an undefined
|
|
|
|
/// state.
|
|
|
|
static void DeleteAll();
|
|
|
|
/// Deletes the memory file data with the given file_name. Any objects open
|
|
|
|
/// with that file name will be in an undefined state.
|
|
|
|
static void Delete(const std::string& file_name);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~MemoryFile() override;
|
|
|
|
bool Open() override;
|
|
|
|
|
|
|
|
private:
|
2015-12-22 00:33:55 +00:00
|
|
|
std::string mode_;
|
2015-12-22 00:20:34 +00:00
|
|
|
std::vector<uint8_t>* file_;
|
|
|
|
uint64_t position_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MemoryFile);
|
|
|
|
};
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2015-12-22 00:20:34 +00:00
|
|
|
|
|
|
|
#endif // MEDIA_FILE_MEDIA_FILE_H_
|