MCPcopy Create free account
hub / github.com/Tencent/UnLua / ReadSize

Method ReadSize

Plugins/UnLua/Source/UnLua/Private/BaseLib/LuaLib_File.cpp:130–159  ·  view source on GitHub ↗

/////FUNCTIONS FOR LUA LIB////////////////////// * @param Size is Size is Zero Means Read All From Current Offset,else means read SizeBytes from current Offset */

Source from the content-addressed store, hash-verified

128 @param Size is Size is Zero Means Read All From Current Offset,else means read SizeBytes from current Offset
129 */
130 FORCEINLINE int ReadSize(TArray<uint8>& Buffer, uint32 Size = 0)
131 {
132 TArray<uint8> DataBuffer;
133 static const int64 DataBufferSize = 10 * 1024;
134 //when file is valid and is read mode or FILEWRITE_AllowRead flag is set
135 if (this->IsReadable())
136 {
137 DataBuffer.AddUninitialized(DataBufferSize);//10K
138 //get file size
139 int64 FileSize = FILE->TotalSize();
140 //get current offset
141 int64 CurPos = FILE->Tell();
142 //compute readable target size(size left to be read from current offset)
143 int64 TargetSize = FileSize - CurPos;
144 int64 ReadSize = 0;
145 if (0 < Size)
146 {
147 TargetSize = FMath::Min(TargetSize, (int64)Size);
148 }
149 while (TargetSize)
150 {
151 CurPos = FILE->Tell();
152 FILE->Serialize(DataBuffer.GetData(), FMath::Min(TargetSize, DataBufferSize));
153 ReadSize = FILE->Tell() - CurPos;
154 TargetSize -= ReadSize;
155 Buffer.Append(DataBuffer.GetData(), ReadSize);
156 }
157 }
158 return Buffer.Num();
159 }
160
161 //ReadLine
162 FORCEINLINE void ReadLine(lua_State *L, bool bWithNewLineCh = false)

Callers 2

ReadBytesMethod · 0.95
UE4File_ReadFileFunction · 0.80

Calls 7

IsReadableMethod · 0.95
AddUninitializedMethod · 0.80
TotalSizeMethod · 0.80
TellMethod · 0.45
GetDataMethod · 0.45
AppendMethod · 0.45
NumMethod · 0.45

Tested by

no test coverage detected