Class Region

extends ServiceResourceProxy
A storage region is a sequence of stored bytes that reside outside the current process and that can be persisted across application and device restarts.
Regions are referred to via a schema and a path. The scheme indicates the volatility and storage medium of the region and the path allows separating regions.

Class summary


SCHEME-FLASH -> any
SCHEME-PARTITION -> any
open uri/string --capacity/int= --writable/bool= -> Region
open --flash/bool path/string --capacity/int= --writable/bool= -> Region
open --partition/bool path/string --capacity/int= --writable/bool= -> Region
open --scheme/string --path/string --capacity/int= --writable/bool= -> Region
Opens a storage region using the given scheme and path.
delete uri/string -> none
delete --flash/bool path/string -> none
delete --scheme/string --path/string -> none
list --flash/bool -> List
Variant of list --scheme.
list --scheme/string -> List
Returns the uri for all existing regions with the given scheme as a list of strings.

Statics

delete uri/string -> none

delete --flash/bool path/string -> none

delete --scheme/string --path/string -> none

list --flash/bool -> List
Variant of list --scheme.
Returns the uri for all existing regions with the SCHEME-FLASH scheme as a list of strings.

list --scheme/string -> List
Returns the uri for all existing regions with the given scheme as a list of strings.

open uri/string --capacity/int=null --writable/bool=true -> Region
Opens a storage region with using the schema and path parsed from the given uri.
The format of the uri is <scheme>:<path> and it is common to use qualified paths that include the domain name of the region owner, e.g. "flash:toitlang.org/jag".

open --flash/bool path/string --capacity/int=null --writable/bool=true -> Region
Opens a storage region using the SCHEME-FLASH scheme and the given path.

open --partition/bool path/string --capacity/int=null --writable/bool=true -> Region
Opens a storage region using the SCHEME-PARTITION scheme and the given path.

open --scheme/string --path/string --capacity/int=null --writable/bool=true -> Region
Opens a storage region using the given scheme and path.
If an existing region matches the scheme and path, it is opened. An exception is thrown if a capacity is provided and the existing region is smaller than that.
If no region that match scheme and path exists, a new one is created. In this case, a non-null capacity must be provided.
If writable is true (default), the region is opened for both reading and writing. If writable is false (use --no-writable), the region is opened just for reading. Opening a partition for writing may require different permissions than opening it just for reading.

Methods

close -> none

erase --from/int=0 --to/int=size -> none
Erases the bytes in the range starting at from and ending at to (exclusive) by setting them to erase-value.
Both from and to must be aligned to erase-granularity.

The erase-granularity is the required alignment of the from and to offsets for calls to erase. As such, it is also the smallest number of bytes that can be erased by calls to erase.

The erase-value is the value of individual erased bytes after a call to erase.

is-erased --from/int=0 --to/int=size -> bool

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

read --from/int bytes/ByteArray -> none

read --from/int --to/int -> ByteArray

stream --from/int=0 --to/int=size --max-size/int=256 -> Reader

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

write --from/int bytes/ByteArray -> none
Deprecated. Use write --at bytes instead.

write --at/int data/Data -> none
Writes the given data into the region at the given offset at.
If the region has already data, the new data might be combined with the existing data. See erase-value, write-can-clear-bits, and write-can-set-bits. Use erase to reset areas to the erase-value after which this method will write the data as given.

Whether a call to write can change individual bits from 1 to 0.

Whether a call to write can change individual bits from 0 to 1.

Fields

The size of the region in bytes.