Device Monitoring Studio - Monitor, log and analyze data coming through PC ports and connections
Docs

IFile Interface

This interface is implemented by a File Object.

Declaration

interface IFile {
    // Properties
    ${currentPosition}: number;
    readonly ${size}: number;
    readonly ${isOpen}: boolean;
    // Methods
    ${read}(size: number, position?: number): Promise<Uint8Array>;
    ${write}(data: number[] | Uint8Array | DataView | ArrayBuffer, position?: number): Promise<number>;
    ${setEnd}(): void;
    ${close}(): void;
}
// This interface is not available in managed environment
// This interface is not available in native environment

IFile Properties

currentPosition

currentPosition: number;
// This property is not available in managed environment
// This property is not available in native environment

This property represents the current file's position.

size

readonly size: number;
// This property is not available in managed environment
// This property is not available in native environment

This property holds the current file's size.

isOpen

readonly isOpen: boolean;
// This property is not available in managed environment
// This property is not available in native environment

This property evaluates to false after calling the IFile.close method.

@returns false after calling IFile.close method, true otherwise.

IFile Methods

read

read(size: number, position?: number): Promise<Uint8Array>;
// This method is not available in managed environment
// This method is not available in native environment
size
The number of bytes to read.
position
Optional starting offset for the operation. If omitted, the file's current position is used (and later updated).

Data read from a file.

Reads data from a file. This method executes asynchronously.

Reading from a file

var data = await file.read(4096);

write

write(data: number[] | Uint8Array | DataView | ArrayBuffer, position?: number): Promise<number>;
// This method is not available in managed environment
// This method is not available in native environment
data
The data to be written.
position
Optional starting offset for the operation. If omitted, the file's current position is used (and later updated).

The number of bytes written.

Writes data to a file. This method executes asynchronously.

Writing to a file

// Copy first 4KB of file to second 4KB

var data = await file.read(4096, 0);
await file.write(data, 4096);

setEnd

setEnd(): void;
// This method is not available in managed environment
// This method is not available in native environment

Changes the size of a file to be the same as IFile.currentPosition.

close

close(): void;
// This method is not available in managed environment
// This method is not available in native environment

Closes the file. File object may not be used after calling this method. Only IFile.isOpen property may safely be used after calling this method.