Storage
FilaSignal has two kinds of named storage. Both keep copies of values under string keys.
| Drive storage | Storage Server | |
|---|---|---|
| Used by | the drive’s own program, as storage |
every program on the network, through a reference |
| Capacity | 64 KiB, 256 keys | 256 KiB, 1,024 keys, 64 KiB per value |
| Lives | in the world save, with the drive | in the block; deleted when the block breaks |
| Read by a computer | drives.from(name).read(key) |
directly |
Storable values
Section titled “Storable values”nil, booleans, numbers, strings, lists, tuples and dictionaries, nested at most 16 levels, without loops. Device
handles and references, constants, class objects and errors cannot be stored. Every read returns a fresh copy: change
it and write it back to update the stored value.
Keys are 1 to 64 characters: letters, digits and _ . : -.
A write is checked completely before anything changes, so a failed write leaves storage as it was.
Drive storage
Section titled “Drive storage”storage.append(key, value)
Append a value to the list under a key, creating it when absent.
ok, err = storage.append("history", entry)storage.clear()
Remove every stored key.
ok, err = storage.clear()storage.delete(key)
Remove a key. Returns false when it was absent.
removed, err = storage.delete("history")storage.has(key)
Test whether a key is stored.
found, err = storage.has("history")storage.keys()
List stored keys in insertion order.
keys, err = storage.keys()storage.read(key)
Read a copy of a stored value. A missing key returns storage.missing.
last, err = storage.read("last_detection")storage.usage()
Read used and capacity bytes and entries and maxEntries.
usage, err = storage.usage()storage.write(key, value)
Store a copy of a value under a key, replacing any old value.
ok, err = storage.write("last_detection", entry)Storage Server
Section titled “Storage Server”Properties: records.connected, records.id, records.kind, records.name. They are read-only.
records.append(key, value)
Add a value to the end of the list under a key, creating the list when needed.
server.append("visitors", name)records.clear()
Remove everything stored on the server.
server.clear()records.delete(key)
Remove a key. Gives false when nothing was stored.
server.delete("old")records.has(key)
True when something is stored under a key.
if server.has("diamonds") { print("stocked") }records.keys()
List the stored keys, oldest first.
names = server.keys()records.read(key)
Read a copy of the value stored under a key. A missing key gives the error storage.missing.
count = server.read("diamonds")records.usage()
Read used and capacity bytes and entries and maxEntries.
space = server.usage()records.write(key, value)
Store a copy of a value under a key, replacing any old value.
server.write("diamonds", 64)Errors
Section titled “Errors”| Code | Meaning |
|---|---|
storage.missing |
Nothing is stored under the key. |
storage.key |
The key is empty, too long or has other characters. |
storage.value |
The value cannot be stored, for example a device or a class object, or it nests too deeply. |
storage.type |
append on a key that holds something other than a list. |
storage.full |
The write would exceed the capacity or the number of keys. |
storage.damaged |
A Storage Server’s saved data could not be read. It is kept unchanged for an operator. |
drive.missing, drive.in_use, drive.damaged |
The drive is gone, in use elsewhere, or its record is damaged. |
host.denied |
A drive program wrote to a Storage Server that only lets device programs read. |
Keeping data small
Section titled “Keeping data small”Storage fills up when a program appends forever. Keep only the newest entries:
on device.entityEnter(entity) { history, err = storage.read("history") if err is not nil { history = [] } history.append(entity.name) while history.length > 50 { history.remove(0) } storage.write("history", history)}