From cfb629735752f9f64350d367bfdcbe6ac014a07c Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 21 Nov 2024 11:28:18 +0100 Subject: [PATCH] Implements streamless and manifestonly calls --- ProjectPlugins/CodexPlugin/CodexAccess.cs | 12 ++++++++++++ ProjectPlugins/CodexPlugin/CodexNode.cs | 14 ++++++++++++-- .../DataTests/ManifestOnlyDownloadTest.cs | 6 ++++-- .../DataTests/StreamlessDownloadTest.cs | 5 ++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexAccess.cs b/ProjectPlugins/CodexPlugin/CodexAccess.cs index e8f755c..8140ff5 100644 --- a/ProjectPlugins/CodexPlugin/CodexAccess.cs +++ b/ProjectPlugins/CodexPlugin/CodexAccess.cs @@ -80,6 +80,18 @@ namespace CodexPlugin return fileResponse.Stream; } + public LocalDataset DownloadStreamless(ContentId cid) + { + var response = OnCodex(api => api.DownloadNetworkAsync(cid.Id)); + return mapper.Map(response); + } + + public LocalDataset DownloadManifestOnly(ContentId cid) + { + var response = OnCodex(api => api.DownloadNetworkManifestAsync(cid.Id)); + return mapper.Map(response); + } + public LocalDatasetList LocalFiles() { return mapper.Map(OnCodex(api => api.ListDataAsync())); diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 43edb1a..fe978c6 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -21,6 +21,8 @@ namespace CodexPlugin ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action onFailure); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, Action onFailure, string fileLabel = ""); + LocalDataset DownloadStreamless(ContentId cid); + LocalDataset DownloadManifestOnly(ContentId cid); LocalDatasetList LocalFiles(); CodexSpace Space(); void ConnectToPeer(ICodexNode node); @@ -37,8 +39,6 @@ namespace CodexPlugin /// void DeleteRepoFolder(); void Stop(bool waitTillStopped); - void DownloadStreamless(ContentId cid); - Manifest DownloadManifestOnly(ContentId cid); } public class CodexNode : ICodexNode @@ -194,6 +194,16 @@ namespace CodexPlugin return file; } + public LocalDataset DownloadStreamless(ContentId cid) + { + return CodexAccess.DownloadStreamless(cid); + } + + public LocalDataset DownloadManifestOnly(ContentId cid) + { + return CodexAccess.DownloadManifestOnly(cid); + } + public LocalDatasetList LocalFiles() { return CodexAccess.LocalFiles(); diff --git a/Tests/CodexReleaseTests/DataTests/ManifestOnlyDownloadTest.cs b/Tests/CodexReleaseTests/DataTests/ManifestOnlyDownloadTest.cs index 3b7de2e..35a0178 100644 --- a/Tests/CodexReleaseTests/DataTests/ManifestOnlyDownloadTest.cs +++ b/Tests/CodexReleaseTests/DataTests/ManifestOnlyDownloadTest.cs @@ -18,14 +18,16 @@ namespace CodexReleaseTests.DataTests var cid = uploader.UploadFile(file); var startSpace = downloader.Space(); - var manifest = downloader.DownloadManifestOnly(cid); + var localDataset = downloader.DownloadManifestOnly(cid); Thread.Sleep(1000); var spaceDiff = startSpace.FreeBytes - downloader.Space().FreeBytes; Assert.That(spaceDiff, Is.LessThan(64.KB().SizeInBytes)); - Assert.That(manifest.OriginalBytes.SizeInBytes, Is.EqualTo(file.GetFilesize().SizeInBytes)); + + Assert.That(localDataset.Cid, Is.EqualTo(cid)); + Assert.That(localDataset.Manifest.OriginalBytes.SizeInBytes, Is.EqualTo(file.GetFilesize().SizeInBytes)); } } } diff --git a/Tests/CodexReleaseTests/DataTests/StreamlessDownloadTest.cs b/Tests/CodexReleaseTests/DataTests/StreamlessDownloadTest.cs index 7f2223b..afd4d2d 100644 --- a/Tests/CodexReleaseTests/DataTests/StreamlessDownloadTest.cs +++ b/Tests/CodexReleaseTests/DataTests/StreamlessDownloadTest.cs @@ -19,7 +19,10 @@ namespace CodexReleaseTests.DataTests var startSpace = downloader.Space(); var start = DateTime.UtcNow; - downloader.DownloadStreamless(cid); + var localDataset = downloader.DownloadStreamless(cid); + + Assert.That(localDataset.Cid, Is.EqualTo(cid)); + Assert.That(localDataset.Manifest.OriginalBytes.SizeInBytes, Is.EqualTo(file.GetFilesize().SizeInBytes)); // TODO: We have no way to inspect the status or progress of the download. // We use local space information to estimate.