downloadStringFile method

String downloadStringFile(
  1. String? url
)

Downloads a file from the specified URL and returns a string.

param url The URL to the file. return The file as a string. throws BiosealException An error has occurred during Bioseal Library execution.

Implementation

String downloadStringFile(String? url) {
  Pointer<Char>? pUrl = url?.toNativeUtf8().cast<Char>();
  Pointer<Char> pData = nullptr;
  Pointer<Int> pDataSize = calloc.allocate(1);
  pDataSize[0] = -1;
  try {
    var err = biosealSDK.id3BiosealResourceCallbackArgs_DownloadStringFile(_pHandle.value, pUrl ?? nullptr, pData, pDataSize);
    if (err == BiosealError.insufficientBuffer.value) {
      pData = calloc.allocate(pDataSize.value);
      err = biosealSDK.id3BiosealResourceCallbackArgs_DownloadStringFile(_pHandle.value, pUrl ?? nullptr, pData, pDataSize);
      if (err != BiosealError.success.value) {
        throw BiosealException(err);
      }
    }
    final vData = utf8.decode(Uint8List.fromList(pData.cast<Uint8>().asTypedList(pDataSize.value)));
    return vData;
  } finally {
    if (pUrl != null) {
      calloc.free(pUrl);
    }
    calloc.free(pData);
    calloc.free(pDataSize);
  }
}