Posted: 20th May 2021 12:28
I currently keep all assets in a single resource file, built using a dotnet app. Reading parts of the file into memblocks is a bit slow using ReadInteger() and ReadByte().

It would be handy if there was an overload for the CreateMemblockFromFile() function that allowed me to specify a starting offset and size.
Posted: 21st May 2021 8:10
I agree such a (built-in) Function would be useful.
With this said., here's said Function in AppGameKit Script.

+ Code Snippet
Function CreateMemblockFromFileblock( MemblockID As Integer, Filename As String, EntryPoint As Integer, SizeInBytes As Integer )
	Local FileID As Integer = 0
	Local FilePos As Integer = 0
	
	FileID = OpenToRead( Filename )
		FilePos = 0
		Repeat
			ReadByte( FileID )
			Inc FilePos
		Until FilePos = EntryPoint
		
		If MemblockID <> 0
			CreateMemblock( MemblockID, SizeInBytes )
		Else
			MemblockID = CreateMemblock( SizeInBytes )
		EndIf
		
		For Offset = 0 To SizeInBytes - 1
			SetMemblockByte( MemblockID, Offset, ReadByte( FileID ) )			
		Next
	CloseFile( FileID )
EndFunction MemblockID
Posted: 22nd May 2021 21:28
I prefer something like this. Is uses SetFilePos for quick file random access and uses ReadInteger() for most of the time to read in 4-bytes chunks.

+ Code Snippet
function LoadMemblockFromFile(filename$, offset, byteLength)
	
	bytes = byteLength
	mem = CreateMemblock(bytes)
	f = OpenToRead(filename$)
	
	SetFilePos(f, offset)
	
	while bytes > 0
		
		if bytes >= 4
			i = ReadInteger(f)	
			SetMemblockInt(mem, byteLength - bytes, i)
			dec bytes, 4
		else
			i = ReadByte(f)
			SetMemblockByte(mem, byteLength - bytes, i)
			dec bytes
		endif
	
	endwhile
	
	CloseFile(f)
	
endfunction mem
Posted: 23rd May 2021 5:51
I'm guessing you are doing some massaging of data but if not there is a CreatememBlockFromFile() function