ezEngine  Milestone 7
ezFileWriter Class Reference

The default class to use to write data to a file, implements the ezStreamWriterBase interface. More...

#include <FileWriter.h>

Inheritance diagram for ezFileWriter:

Public Member Functions

 ezFileWriter ()
 Constructor, does nothing.
 
 ~ezFileWriter ()
 Destructor, closes the file, if it is still open (RAII).
 
ezResult Open (const char *szFile, ezUInt32 uiCacheSize=1024 *1024, bool bAllowFileEvents=true)
 Opens the given file for writing. Returns EZ_SUCCESS if the file could be opened. A cache is created to speed up small writes. More...
 
void Close ()
 Closes the file, if it is open.
 
virtual ezResult WriteBytes (const void *pWriteBuffer, ezUInt64 uiBytesToWrite) override
 Writes the given number of bytes to the file. Returns EZ_SUCCESS if all bytes were successfully written. More...
 
virtual ezResult Flush () override
 Will write anything that's currently in the write-cache to disk. Will decrease performance if used excessively. More...
 
- Public Member Functions inherited from ezFileWriterBase
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 ezStreamWriterBase
 ezStreamWriterBase ()
 Constructor.
 
virtual ~ezStreamWriterBase ()
 Virtual destructor to ensure correct cleanup.
 
template<typename T >
ezResult WriteWordValue (const T *pWordValue)
 Helper method to write a word value correctly (copes with potentially different endianess)
 
template<typename T >
ezResult WriteDWordValue (const T *pDWordValue)
 Helper method to write a dword value correctly (copes with potentially different endianess)
 
template<typename T >
ezResult WriteQWordValue (const T *pQWordValue)
 Helper method to write a qword value correctly (copes with potentially different endianess)
 

Private Member Functions

 EZ_DISALLOW_COPY_AND_ASSIGN (ezFileWriter)
 

Private Attributes

ezUInt64 m_uiCacheWritePosition
 
ezDynamicArray< ezUInt8 > m_Cache
 

Additional Inherited Members

- Protected Member Functions inherited from ezFileWriterBase
ezDataDirectoryWriterGetFileWriter (const char *szFile, bool bAllowFileEvents)
 
- Protected Attributes inherited from ezFileWriterBase
ezDataDirectoryWriterm_pDataDirWriter
 

Detailed Description

The default class to use to write data to a file, implements the ezStreamWriterBase interface.

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

Member Function Documentation

ezResult ezFileWriter::Flush ( )
overridevirtual

Will write anything that's currently in the write-cache to disk. Will decrease performance if used excessively.

Note
Flush only guarantees that the data is sent through the OS file functions. It does not guarantee that the OS actually wrote the data on the disk, it might still use buffer itself and thus an application that crashes might still see data loss even when 'Flush' had been called.

Reimplemented from ezStreamWriterBase.

ezResult ezFileWriter::Open ( const char *  szFile,
ezUInt32  uiCacheSize = 1024 * 1024,
bool  bAllowFileEvents = true 
)

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

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.

ezResult ezFileWriter::WriteBytes ( const void *  pWriteBuffer,
ezUInt64  uiBytesToWrite 
)
overridevirtual

Writes the given number of bytes to the file. Returns EZ_SUCCESS if all bytes were successfully written.

As this class buffers writes with an internal cache, EZ_SUCCESS does NOT mean that the data is actually written to disk.

Implements ezStreamWriterBase.


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