PicoStorage Code Samples
Hello world
Creates a file in the root directory, and writes some text to it
We start by including the header "PicoStorage.hpp", which gets in all the other relevant headers.
All library's names are contained in the namespace "PicoStorage"; in order to avoid typing the namespace in full, we recommend using a shorter namespace alias:
namespace pico = PicoStorage; pico::Dir root = pico::openStorage(location);
We create a new storage, indicating the filesystem file which will keep the storage. Creation will fail if the file is already existing, in which situation create() returns false. Learn more about PicoStorage's return codes and exception handling.
Next, inside the root directory we create a new file and write a text to this file.
We commit the modifications. There's no need to 'close' the files or directories.
Large Directory and Dir::Iterator
Creates many entries in the root directory, and iterates over all the entries
For concision we prefer the using namespace PicoStorage; instead of the namespace alias in these small example.
First, we delete an eventual pre-existing storage file (OsDir::remove(storage))
When opening the storage, we specify a cache size bigger then the default
We create a large number of files. The file name is file number in binary.
Next we iterate over all entries in the directory, and check that all the files created previously are there