sdlxLoadFile function iostream

({Uint8List data, int datasize})? sdlxLoadFile(
  1. String file
)

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

({Uint8List data, int datasize})? sdlxLoadFile(String file) {
  var datasize = 0;
  final datasizePointer = ffi.calloc<Size>();
  final dataPointer = sdlLoadFile(file, datasizePointer);
  datasize = datasizePointer.value;
  datasizePointer.callocFree();
  if (dataPointer == nullptr) {
    return null;
  }
  final data = Uint8List.fromList(
    dataPointer.cast<Uint8>().asTypedList(datasize),
  );
  sdlFree(dataPointer.cast<Void>());
  return (data: data, datasize: datasize);
}