// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Platform/Types.h"
#include "ReadStream.h"
///
/// Implementation of the stream that has access to the file and is optimized for fast reading from it
///
///
class FLAXENGINE_API FileReadStream : public ReadStream
{
private:
File* _file;
uint32 _virtualPosInBuffer; // Current position in the buffer (index)
uint32 _bufferSize; // Amount of loaded bytes from the file to the buffer
byte _buffer[FILESTREAM_BUFFER_SIZE];
public:
NON_COPYABLE(FileReadStream);
///
/// Init
///
/// File to read
FileReadStream(File* file);
///
/// Destructor
///
~FileReadStream();
public:
///
/// Gets the file handle.
///
/// File
FORCE_INLINE const File* GetFile() const
{
return _file;
}
///
/// Unlink file object passed via constructor
///
void Unlink();
public:
///
/// Open file to write data to it
///
/// Path to the file
/// Created file reader stream or null if cannot perform that action
static FileReadStream* Open(const StringView& path);
public:
// [ReadStream]
void Flush() final override;
void Close() final override;
uint32 GetLength() override;
uint32 GetPosition() override;
void SetPosition(uint32 seek) override;
void ReadBytes(void* data, uint32 bytes) override;
};