Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter SixFile Functions (continued)

FileToBuffer Function

Overview

The FileToBuffer function loads the contents of a file into a contiguous buffer.

Syntax/Parameters

Syntax

int = FileToBuffer ( string name, var buffer, [int size] );

Parameters

name

A string containing a qualified filename and path. This parameter supports UTF encoding for filenames with Unicode characters.

buffer

A variable (typically a char or byte array) that will receive the resulting data. The buffer type must resolve to integer base type.

size

An optional int specifying the size of the data to read in bytes. If omitted, size is set to the size of the buffer parameter or to the file’s size. See Remarks below.

Return Value

Returns a int specifying the number of bytes read or 0 on failure. Since a file can be empty, 0 can be a valid value. Use the GetLastError function to retrieve error information. Additional narrative error information is available using the GetLastErrorMessage function.

Remarks

The file is opened with read and write share options and closed upon completion of the read operation.

The buffer parameter is typically a fix character or byte array, however, can be any type so long as it resolves into integer type data. For multiple dimension arrays, the data is essentially poured into the memory area without regard to axis size.

If buffer is declared as auto allocate (empty [ ]), the read operation will automatically expand the size of the array to accommodate the incoming data so long as the size parameter has not been provided. Auto allocation works only on a single-dimension arrays. The depth of the array is set to the size of the area rounded up by the size of the variable elements. For example, an int array will always have a total byte size in increments of four. See Section 3.6 Dimensional Data for more information on allocation.

If the buffer cannot be expanded and the incoming data is too large for the buffer, the entire buffer will be loaded and an ERROR_OVERFLOW condition set. Use the IsError or GetLastError function to check for an overflow.

If the file is larger than the buffer, an ERROR_OVERFLOW condition will be set and the returned bytes will equal the size requested or maximum size.

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Legato IDE, Legato Basic