Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MicropythonFsHex

Manage filesystem files in one or multiple MicroPython hex files.

Hierarchy

  • MicropythonFsHex

Implements

Constructors

constructor

  • File System manager constructor.

    At the moment it needs a MicroPython hex string without files included. Multiple MicroPython images can be provided to generate a Universal Hex.

    throws

    {Error} When any of the input iHex contains filesystem files.

    throws

    {Error} When any of the input iHex is not a valid MicroPython hex.

    Parameters

    • intelHex: string | IntelHexWithId[]

      MicroPython Intel Hex string or an array of Intel Hex strings with their respective board IDs.

    • Default value __namedParameters: object = {}
      • maxFsSize: number

    Returns MicropythonFsHex

Methods

append

  • append(filename: string, content: string): void

create

  • create(filename: string, content: string | Uint8Array): void
  • Create a new file and add it to the file system.

    throws

    {Error} When the file already exists.

    throws

    {Error} When an invalid filename is provided.

    throws

    {Error} When invalid file data is provided.

    Parameters

    • filename: string

      Name for the file.

    • content: string | Uint8Array

      File content to write.

    Returns void

exists

  • exists(filename: string): boolean
  • Check if a file is already present in the file system.

    Parameters

    • filename: string

      Name for the file to check.

    Returns boolean

    True if it exists, false otherwise.

getIntelHex

  • Generate a new copy of the MicroPython Intel Hex with the files in the filesystem included.

    throws

    {Error} When a file doesn't have any data.

    throws

    {Error} When there are issues calculating file system boundaries.

    throws

    {Error} When there is no space left for a file.

    throws

    {Error} When the board ID is not found.

    throws

    {Error} When there are multiple MicroPython hexes and board ID is not provided.

    Parameters

    • Optional boardId: number | microbitBoardId

      When multiple MicroPython hex files are provided select one via this argument.

    Returns string

    A new string with MicroPython and the filesystem included.

getIntelHexBytes

  • Generate a byte array of the MicroPython and filesystem data.

    throws

    {Error} When a file doesn't have any data.

    throws

    {Error} When there are issues calculating file system boundaries.

    throws

    {Error} When there is no space left for a file.

    throws

    {Error} When the board ID is not found.

    throws

    {Error} When there are multiple MicroPython hexes and board ID is not provided.

    Parameters

    • Optional boardId: number | microbitBoardId

      When multiple MicroPython hex files are provided select one via this argument.

    Returns Uint8Array

    A Uint8Array with MicroPython and the filesystem included.

getStorageRemaining

  • getStorageRemaining(): number

getStorageSize

  • getStorageSize(): number
  • The available filesystem total size either calculated by the MicroPython hex or the max storage size limit has been set.

    Returns number

    Size of the filesystem in bytes.

getStorageUsed

  • getStorageUsed(): number

getUniversalHex

  • getUniversalHex(): string
  • Generate a new copy of a MicroPython Universal Hex with the files in the filesystem included.

    throws

    {Error} When a file doesn't have any data.

    throws

    {Error} When there are issues calculating file system boundaries.

    throws

    {Error} When there is no space left for a file.

    throws

    {Error} When this method is called without having multiple MicroPython hexes.

    Returns string

    A new Universal Hex string with MicroPython and filesystem.

importFilesFromHex

  • importFilesFromHex(hexStr: string, options?: ImportOptions): string[]
  • Read the files included in a MicroPython Universal or Intel Hex string and add them to this instance.

    throws

    {Error} When there are no files to import from the hex.

    throws

    {Error} When in the Universal Hex the files of the individual hexes are different.

    throws

    {Error} When there is a problem reading files from one of the hex.

    throws

    {Error} When a filename already exists in this instance (all other files are still imported).

    Parameters

    • hexStr: string

      MicroPython Intel or Universal Hex string with files.

    • Default value options: ImportOptions = {}

    Returns string[]

    A filename list of added files.

importFilesFromIntelHex

  • importFilesFromIntelHex(intelHex: string, __namedParameters?: object): string[]
  • Read the files included in a MicroPython hex string and add them to this instance.

    throws

    {Error} When there are no files to import in the hex.

    throws

    {Error} When there is a problem reading the files from the hex.

    throws

    {Error} When a filename already exists in this instance (all other files are still imported).

    Parameters

    • intelHex: string

      MicroPython hex string with files.

    • Default value __namedParameters: object = {}
      • formatFirst: boolean

        Erase all the previous files before importing. It only erases the files after there are no error during hex file parsing.

      • overwrite: boolean

        Flag to overwrite existing files in this instance.

    Returns string[]

    A filename list of added files.

importFilesFromUniversalHex

  • importFilesFromUniversalHex(universalHex: string, __namedParameters?: object): string[]
  • Read the files included in a MicroPython Universal Hex string and add them to this instance.

    throws

    {Error} When there are no files to import from one of the hex.

    throws

    {Error} When the files in the individual hex are different.

    throws

    {Error} When there is a problem reading files from one of the hex.

    throws

    {Error} When a filename already exists in this instance (all other files are still imported).

    Parameters

    • universalHex: string

      MicroPython Universal Hex string with files.

    • Default value __namedParameters: object = {}
      • formatFirst: boolean

        Erase all the previous files before importing. It only erases the files after there are no error during hex file parsing.

      • overwrite: boolean

        Flag to overwrite existing files in this instance.

    Returns string[]

    A filename list of added files.

ls

  • ls(): string[]

read

  • read(filename: string): string
  • Read the text from a file.

    throws

    {Error} When invalid file name is provided.

    throws

    {Error} When file is not in the file system.

    Parameters

    • filename: string

      Name of the file to read.

    Returns string

    Text from the file.

readBytes

  • readBytes(filename: string): Uint8Array
  • Read the bytes from a file.

    throws

    {Error} When invalid file name is provided.

    throws

    {Error} When file is not in the file system.

    Parameters

    • filename: string

      Name of the file to read.

    Returns Uint8Array

    Byte array from the file.

remove

  • remove(filename: string): void
  • Delete a file from the file system.

    throws

    {Error} When invalid file name is provided.

    throws

    {Error} When the file doesn't exist.

    Parameters

    • filename: string

      Name of the file to delete.

    Returns void

setStorageSize

  • setStorageSize(size: number): void
  • Sets a storage size limit. Must be smaller than available space in MicroPython.

    Parameters

    • size: number

      Size in bytes for the filesystem.

    Returns void

size

  • size(filename: string): number
  • Returns the size of a file in bytes.

    throws

    {Error} When invalid file name is provided.

    throws

    {Error} When the file doesn't exist.

    Parameters

    • filename: string

      Name for the file to check.

    Returns number

    Size file size in bytes.

write

  • write(filename: string, content: string | Uint8Array): void
  • Write a file into the file system. Overwrites a previous file with the same name.

    throws

    {Error} When an invalid filename is provided.

    throws

    {Error} When invalid file data is provided.

    Parameters

    • filename: string

      Name for the file.

    • content: string | Uint8Array

      File content to write.

    Returns void

Generated using TypeDoc