sdlxLoadFile function iostream

bool sdlxLoadFile(
  1. String file,
  2. SdlxDataResult result
)

Load all the data from a file path.

The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in the value reported via datasize.

The data should be freed with SDL_free().

\param file the path to read all available data from. \param datasize if not NULL, will store the number of bytes read. \returns the data or NULL on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.2.0.

\sa SDL_LoadFile_IO \sa SDL_SaveFile

extern SDL_DECLSPEC void * SDLCALL SDL_LoadFile(const char *file, size_t *datasize)

Implementation

bool sdlxLoadFile(String file, SdlxDataResult result) {
  var bl = false;
  final datasizePointer = ffi.calloc<Size>();
  final dataPointer = sdlLoadFile(file, datasizePointer);
  if (dataPointer != nullptr) {
    bl = true;
    result
      ..data = Uint8List.fromList(
        dataPointer.cast<Uint8>().asTypedList(datasizePointer.value),
      )
      ..datasize = datasizePointer.value;
    sdlFree(dataPointer);
  }
  datasizePointer.callocFree();
  return bl;
}