Skip to content

memoryBuffer

Use memoryBuffer to read from and write to a memory buffer at shell application level. Large amounts of data that would be unnecessary to transfer between the web application and the native shell application can be stored here and used with SPI directly.

import { SPI, memoryBuffer } from 'miletus';

...

let spi = new SPI();
await spi.open('spi0');

let load = memoryBuffer.loadFile('path_to_my_file');
if (load) {
    spi.writeMemBuffer();
}

Methods

loadFile(filename)

  • filename string - Path to the file.

Load a file into the memory buffer.

Returns Promise<boolean> - Resolves with a boolean value indicating the success of the file loading.

saveFile(filename)

  • filename string - Path to the file.

Save the contents of the memory buffer into a file.

Returns Promise<boolean> - Resolves with a boolean value indicating the success of the file saving.

clear()

Clear the memory buffer.

Returns Promise<boolean> - Resolves with a boolean value indicating the success of the memory buffer clearing.

readBuffer(length[, pos])

  • length number - The length of the data to read.
  • pos number (optional) - The position from which to read. Default value is 0.

Read data from the memory buffer into the web application from a given position.

Returns Promise<ArrayBuffer> - Resolves with an ArrayBuffer that contains the data.

writeBuffer(buffer, length[, pos])

  • buffer ArrayBuffer | Uint8Array | number[] - Buffer to write.
  • length number - Length of the data to write.
  • pos number (optional) - Position in the memory buffer. Default value is 0.

Write a buffer of data from the web application to the memory buffer.

Returns Promise<boolean> - Resolves with a boolean value indicating the success of the buffer write.