ezEngine  Release 25.03
ezFileReader Class Reference

The default class to use to read data from a file, implements the ezStreamReader interface. More...

#include <FileReader.h>

Inheritance diagram for ezFileReader:

Public Member Functions

 ezFileReader ()=default
 Constructor, does nothing.
 
 ~ezFileReader ()
 Destructor, closes the file, if it is still open (RAII).
 
ezResult Open (ezStringView sFile, ezUInt32 uiCacheSize=1024 *64, ezFileShareMode::Enum fileShareMode=ezFileShareMode::Default, bool bAllowFileEvents=true)
 Opens the given file for reading. Returns EZ_SUCCESS if the file could be opened. A cache is created to speed up small reads. More...
 
void Close ()
 Closes the file, if it is open.
 
virtual ezUInt64 ReadBytes (void *pReadBuffer, ezUInt64 uiBytesToRead) override
 Attempts to read the given number of bytes into the buffer. Returns the actual number of bytes read.
 
virtual ezUInt64 SkipBytes (ezUInt64 uiBytesToSkip) override
 Helper method to skip a number of bytes. Returns the actual number of bytes skipped.
 
bool IsEOF () const
 Whether the end of the file was reached during reading. More...
 
- Public Member Functions inherited from ezFileReaderBase
ezString128 GetFilePathAbsolute () const
 Returns the absolute path with which the file was opened (including the prefix of the data directory).
 
ezString128 GetFilePathRelative () const
 Returns the relative path of the file within its data directory (excluding the prefix of the data directory).
 
ezDataDirectoryTypeGetDataDirectory () const
 Returns the ezDataDirectoryType over which this file has been opened.
 
bool IsOpen () const
 Returns true, if the file is currently open.
 
ezUInt64 GetFileSize () const
 Returns the current total size of the file.
 
- Public Member Functions inherited from ezStreamReader
 ezStreamReader ()
 Constructor.
 
virtual ~ezStreamReader ()
 Virtual destructor to ensure correct cleanup.
 
template<typename T >
ezResult ReadWordValue (T *pWordValue)
 Helper method to read a word value correctly (copes with potentially different endianess)
 
template<typename T >
ezResult ReadDWordValue (T *pDWordValue)
 Helper method to read a dword value correctly (copes with potentially different endianess)
 
template<typename T >
ezResult ReadQWordValue (T *pQWordValue)
 Helper method to read a qword value correctly (copes with potentially different endianess)
 
template<typename ArrayType , typename ValueType >
ezResult ReadArray (ezArrayBase< ValueType, ArrayType > &inout_array)
 Reads an array of elements from the stream.
 
template<typename ValueType , ezUInt16 uiSize, typename AllocatorWrapper >
ezResult ReadArray (ezSmallArray< ValueType, uiSize, AllocatorWrapper > &ref_array)
 Reads a small array of elements from the stream.
 
template<typename ValueType , ezUInt32 uiSize>
ezResult ReadArray (ValueType(&array)[uiSize])
 Writes a C style fixed array.
 
template<typename KeyType , typename Comparer >
ezResult ReadSet (ezSetBase< KeyType, Comparer > &inout_set)
 Reads a set.
 
template<typename KeyType , typename ValueType , typename Comparer >
ezResult ReadMap (ezMapBase< KeyType, ValueType, Comparer > &inout_map)
 Reads a map.
 
template<typename KeyType , typename ValueType , typename Hasher >
ezResult ReadHashTable (ezHashTableBase< KeyType, ValueType, Hasher > &inout_hashTable)
 Read a hash table (note that the entry order is not stable)
 
ezResult ReadString (ezStringBuilder &ref_sBuilder)
 Reads a string into an ezStringBuilder.
 
ezResult ReadString (ezString &ref_sString)
 Reads a string into an ezString.
 
EZ_ALWAYS_INLINE ezTypeVersion ReadVersion (ezTypeVersion expectedMaxVersion)
 

Additional Inherited Members

- Protected Member Functions inherited from ezFileReaderBase
ezDataDirectoryReaderGetFileReader (ezStringView sFile, ezFileShareMode::Enum FileShareMode, bool bAllowFileEvents)
 
- Protected Attributes inherited from ezFileReaderBase
ezDataDirectoryReaderm_pDataDirReader
 

Detailed Description

The default class to use to read data from a file, implements the ezStreamReader interface.

This file reader buffers reads up to a certain amount of bytes (configurable). It closes the file automatically once it goes out of scope.

Member Function Documentation

◆ IsEOF()

bool ezFileReader::IsEOF ( ) const
inline

Whether the end of the file was reached during reading.

Note
This is not 100% accurate, it does not guarantee that if it returns false, that the next read will return any data.

◆ Open()

ezResult ezFileReader::Open ( ezStringView  sFile,
ezUInt32  uiCacheSize = 1024 * 64,
ezFileShareMode::Enum  fileShareMode = ezFileShareMode::Default,
bool  bAllowFileEvents = true 
)

Opens the given file for reading. Returns EZ_SUCCESS if the file could be opened. A cache is created to speed up small reads.

You should typically not disable bAllowFileEvents, unless you need to prevent recursive file events, which is only the case, if you are doing file accesses from within a File Event Handler.


The documentation for this class was generated from the following files: