sdlLoadFileAsync function

bool sdlLoadFileAsync(
  1. String? file,
  2. Pointer<SdlAsyncIoQueue> queue,
  3. Pointer<NativeType> userdata
)

Load all the data from a file path, asynchronously.

This function returns as quickly as possible; it does not wait for the read to complete. On a successful return, this work will continue in the background. If the work begins, even failure is asynchronous: a failing return value from this function only means the work couldn't start at all.

The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in SDL_AsyncIOOutcome's bytes_transferred value.

This function will allocate the buffer to contain the file. It must be deallocated by calling SDL_free() on SDL_AsyncIOOutcome's buffer field after completion.

An SDL_AsyncIOQueue must be specified. The newly-created task will be added to it when it completes its work.

\param file the path to read all available data from. \param queue a queue to add the new SDL_AsyncIO to. \param userdata an app-defined pointer that will be provided with the task results. \returns true on success or false on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.2.0.

\sa SDL_LoadFile_IO

extern SDL_DECLSPEC bool SDLCALL SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata)

Implementation

bool sdlLoadFileAsync(String? file, Pointer<SdlAsyncIoQueue> queue,
    Pointer<NativeType> userdata) {
  final sdlLoadFileAsyncLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(Pointer<Utf8> file, Pointer<SdlAsyncIoQueue> queue,
          Pointer<NativeType> userdata),
      int Function(Pointer<Utf8> file, Pointer<SdlAsyncIoQueue> queue,
          Pointer<NativeType> userdata)>('SDL_LoadFileAsync');
  final filePointer = file != null ? file.toNativeUtf8() : nullptr;
  final result =
      sdlLoadFileAsyncLookupFunction(filePointer, queue, userdata) == 1;
  calloc.free(filePointer);
  return result;
}