Platforms to show: All Mac Windows Linux Cross-Platform

Back to FolderItem class.

FolderItem.ReadFileMBS(byref data as MemoryBlock, offset As Integer = 0, byteCount As Integer = -1) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS Util Plugin 21.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Reads a file to a memory block.
Example
Dim f As New FolderItem("/Users/cs/Downloads/Download Archive/Xcode_13_beta_5.xip", FolderItem.PathModes.Native)

Var m As MemoryBlock
'Dim m As New MemoryBlock(f.Length)

If f.ReadFileMBS(m) Then
// okay
Var Len As Integer = m.size
Break
Else
// failed
Var e As Integer = f.LastErrorCode
Break
End If

Reads content of file and returns it in data parameter.
Returns true on success of false on failure.

See also WriteFileMBS function.

If the MemoryBlock is nil, we create one.
If the MemoryBlock is not nil and has right size, we use it, otherwise we create a new one.
Not intended for files >2 GB.

Added offset and length parameters in version 23.1.
If byteCount is negative, we read whole file. If byteCount is bigger than file, we only read the available portion.

See also:

Some examples using this method:

FolderItem.ReadFileMBS(byref data as string, offset As Integer = 0, byteCount As Integer = -1) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Files MBS Util Plugin 19.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Reads a file.

Reads content of file and returns it in data parameter.
Returns true on success of false on failure.

See also WriteFileMBS function.

Limited to maximum size of a string (2 GB)
Data must fit in memory, so 32-bit processes may be limited to reading less than 2 GB.

Added offset and length parameters in version 23.1.
If byteCount is negative, we read whole file. If byteCount is bigger than file, we only read the available portion.

See also:

Some examples using this method:

Blog Entries

Xojo Developer Magazine

Videos

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...