Navigation
API > API/Runtime > API/Runtime/Core > API/Runtime/Core/FFileHelper
Description
Load a binary file a block at a time into a buffer and call the visitor each time the buffer is populated with a new block. This uses less memory and has higher cache coherency than loading the entire file into a block of bytes, and is more performant than reading the file a byte at a time. Useful for e.g. hashing or parsing.
| Name | LoadFileInBlocks |
| Type | function |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/FileHelper.h |
| Include Path | #include "Misc/FileHelper.h" |
| Source | /Engine/Source/Runtime/Core/Private/Misc/FileHelper.cpp |
static bool LoadFileInBlocks
(
FStringView Filename,
TFunctionRef < void> BlockVisitor,
int64 Offset,
int64 Size,
uint32 Flags,
int64 BlockSize
)
Parameters
| Name | Remarks |
|---|---|
| Filename | The file to read |
| BlockVisitor | Function called repeatedly with each sequential block. Size of the input might change for performance and should not be assumed. Possibly the entire file will be passed in a single block. If LoadFileInBlocks returns true, the sum of sizes in each call to BlockVisitor equals the size of the requested range of the the file on disk. If the requested range has size 0, LoadFileInBlocks will return true and the BlockVisitor will not be called. |
| Offset | Start of the range of bytes to read from the file. If less than zero or larger than filesize, it will be silently clamped to the [0,FileSize] range. This may result in LoadFileInBlocks returning true but using an empty range and not calling BlockVisitor. |
| Length | of the range of bytes to read from the file. If less than zero, all bytes between Offset and end of file are read. If larger than the size of the range between Offset and end of file, it will be silently shortened to the size of the range. |
| Flags | Flags to pass to IFileManager::CreateFileReader |
| BlockSize | Size of the internally-allocated buffer to read bytes into and pass to each call to BlockVisitor. Sizes <= 0 use the default-selected block size for the current platform. |