sdlxReadStorageFile function storage
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)
Implementation
Uint8List? sdlxReadStorageFile(Pointer<SdlStorage> storage, String path) {
Uint8List? result;
final length = sdlxGetStorageFileSize(storage, path);
if (length != null) {
final destinationPointer = ffi.calloc<Uint8>(length);
final bl = sdlReadStorageFile(
storage,
path,
destinationPointer.cast<Void>(),
length,
);
if (bl) {
result = Uint8List.fromList(destinationPointer.asTypedList(length));
}
destinationPointer.callocFree();
}
return result;
}