public async Task <DownloadOperation> DownloadObjectAsync(Bucket bucket, string targetPath, DownloadOptions downloadOptions, bool immediateStart = true) { var downloadOptionsSWIG = downloadOptions.ToSWIG(); SWIG.DownloadResult downloadResult = await Task.Run(() => SWIG.storj_uplink.download_object(_access._project, bucket.Name, targetPath, downloadOptionsSWIG)); if (downloadResult.error != null && !string.IsNullOrEmpty(downloadResult.error.message)) { throw new ObjectNotFoundException(targetPath, downloadResult.error.message); } SWIG.ObjectResult objectResult = await Task.Run(() => SWIG.storj_uplink.download_info(downloadResult.download)); if (objectResult.error != null && !string.IsNullOrEmpty(objectResult.error.message)) { throw new ObjectNotFoundException(targetPath, objectResult.error.message); } DownloadOperation download = new DownloadOperation(downloadResult, objectResult.object_.system.content_length, targetPath); if (immediateStart) { download.StartDownloadAsync(); //Don't await it, otherwise it would "block" DownloadObjectAsync } SWIG.storj_uplink.free_object_result(objectResult); return(download); }
internal DownloadOperation(SWIG.DownloadResult downloadResult, long totalBytes, string objectName) { _downloadResult = downloadResult; TotalBytes = totalBytes; _bytesToDownload = new byte[TotalBytes]; ObjectName = objectName; }
public void Dispose() { if (_downloadResult != null) { SWIG.storj_uplink.free_download_result(_downloadResult); _downloadResult.Dispose(); _downloadResult = null; } }
public DownloadStream(Bucket bucket, int totalBytes, string objectName, Access access) //TODO: better access-handling { string error; _length = totalBytes; _bucket = bucket; _objectName = objectName; _access = access; _downloadResult = SWIG.storj_uplink.download_object(_access._project, bucket.Name, objectName, null); //TODO: make DownloadOptions available to caller _download = new DownloadOperation(_downloadResult, totalBytes, objectName); if (!_download.Running && !_download.Completed && !_download.Cancelled && !_download.Failed) { _download.StartDownloadAsync(); } }