os.mmap
Reads the whole file and returns its binary data as an ArrayBuffer.
mmap(filename)Examples
Map the binary data of a file.
javascript
function ab2str(buf) {
let arr = new Uint8Array(buf)
return String.fromCharCode.apply(null, arr)
}
function main() {
let buffer = os.mmap("strategyConfig/testData.txt")
Log("File size in bytes:", buffer.byteLength)
let arr = Array.from(new Uint8Array(buffer))
Log("arr:", arr)
// Output: arr: [72,101,108,108,111,32,70,77,90,33]
Log("ab2str(buffer):", ab2str(buffer))
// Output: ab2str(buffer): Hello FMZ!
}Returns
| Type | Description |
ArrayBuffer | Returns the binary data of the file content. |
Arguments
| Name | Type | Required | Description |
filename | string | Yes | File path. |
See Also
Remarks
Reads the entire file into memory at once and returns it as an ArrayBuffer (it is not an on-demand memory mapping; a large file takes the same amount of memory).