sdlxReadStorageFile function storage

Uint8List? sdlxReadStorageFile(
  1. Pointer<SdlStorage> storage,
  2. String path
)

Synchronously read a file from a storage container into a client-provided buffer.

The value of length must match the length of the file exactly; call SDL_GetStorageFileSize() to get this value. This behavior may be relaxed in a future release.

\param storage a storage container to read from. \param path the relative path of the file to read. \param destination a client-provided buffer to read the file into. \param length the length of the destination buffer. \returns true if the file was read or false on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.2.0.

\sa SDL_GetStorageFileSize \sa SDL_StorageReady \sa SDL_WriteStorageFile

extern SDL_DECLSPEC bool SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length)

See also:

Implementation

Uint8List? sdlxReadStorageFile(Pointer<SdlStorage> storage, String path) {
  final length = sdlxGetStorageFileSize(storage, path);
  if (length == null) {
    return null;
  }

  return ffi.using((arena) {
    final destinationPointer = arena<Uint8>(length);
    if (!sdlReadStorageFile(
      storage,
      path,
      destinationPointer.cast<Void>(),
      length,
    )) {
      return null;
    }

    return Uint8List.fromList(destinationPointer.asTypedList(length));
  });
}