Asset OTA


Since 5.5.0:

The ApplicationAsset class is a container that refers to an asset in the system and allows you to stream the contents. When you use System.onAssetOta or System.assetsAvailable, you will be passed a Vector of ApplicationAsset objects. You will typically iterate this vector and process each asset in the asset bundle.

You can read the data byte-by-byte or by buffer. Because it inherits from Stream class, you can use those methods as well.

name() - ApplicationAsset

String name() const;

Returns the asset filename as a String. This is relative to the asset directory and does not include the name of the asset directory when you generated the bundle.

hash() - ApplicationAsset

AssetHash hash() const;

Returns the SHA-256 hash of the asset. See AssetHash for more information.

size() - ApplicationAsset

size_t size() const;

Returns the size of the asset in bytes. This is unaffected by the current read position.

storageSize() - ApplicationAsset

size_t storageSize() const;

Returns how many bytes the asset takes on the device storage. This is typically smaller than size() since assets are stored compressed.

isValid() - ApplicationAsset

bool isValid() const;

Returns true if the asset appears to be valid (has a name and a hash).

isReadable() - ApplicationAsset

bool isReadable();

Returns true if there are bytes to read (asset not empty, not at end of file).

available() - ApplicationAsset

int available() override;

Returns the number of bytes available to read, or 0 if at end of the asset or an error occurred. available() may not return the total size of the asset on the first call. For that, use size().

read() - ApplicationAsset

int read() override;
virtual int read(char* buffer, size_t size);

Read and return a single byte, or read multiple bytes into your buffer.

Even though the buffer is a char * it can be binary data, and is not null terminated. The return value for reading a buffer is the number of bytes read, or a negative system error code.

peek() - ApplicationAsset

int peek() override;
virtual int peek(char* buffer, size_t size);

Read data into a buffer without consuming it, so the next read will re-read the data. Streams are not seekable or rewindable.

skip() - ApplicationAsset

virtual int skip(size_t size);

Skip the specified number of bytes so the next read(), readBuffer(), etc. will read from that point. Streams are not backward seekable, however you can reset() the stream to rewind it back to the beginning.

reset() - ApplicationAsset

virtual void reset();

Resets the internal state of the ApplicationAsset. You can use this to rewind the stream back to the beginning and process it over again from the first byte.

A common use case is when your external peripheral did not complete the update successfully and you want to try again immediately.