Implements streamless and manifestonly calls

This commit is contained in:
Ben 2024-11-21 11:28:18 +01:00
parent f1f3b0f173
commit cfb6297357
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
4 changed files with 32 additions and 5 deletions

View File

@ -80,6 +80,18 @@ namespace CodexPlugin
return fileResponse.Stream; 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() public LocalDatasetList LocalFiles()
{ {
return mapper.Map(OnCodex(api => api.ListDataAsync())); return mapper.Map(OnCodex(api => api.ListDataAsync()));

View File

@ -21,6 +21,8 @@ namespace CodexPlugin
ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action<Failure> onFailure); ContentId UploadFile(TrackedFile file, string contentType, string contentDisposition, Action<Failure> onFailure);
TrackedFile? DownloadContent(ContentId contentId, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, string fileLabel = "");
TrackedFile? DownloadContent(ContentId contentId, Action<Failure> onFailure, string fileLabel = ""); TrackedFile? DownloadContent(ContentId contentId, Action<Failure> onFailure, string fileLabel = "");
LocalDataset DownloadStreamless(ContentId cid);
LocalDataset DownloadManifestOnly(ContentId cid);
LocalDatasetList LocalFiles(); LocalDatasetList LocalFiles();
CodexSpace Space(); CodexSpace Space();
void ConnectToPeer(ICodexNode node); void ConnectToPeer(ICodexNode node);
@ -37,8 +39,6 @@ namespace CodexPlugin
/// </summary> /// </summary>
void DeleteRepoFolder(); void DeleteRepoFolder();
void Stop(bool waitTillStopped); void Stop(bool waitTillStopped);
void DownloadStreamless(ContentId cid);
Manifest DownloadManifestOnly(ContentId cid);
} }
public class CodexNode : ICodexNode public class CodexNode : ICodexNode
@ -194,6 +194,16 @@ namespace CodexPlugin
return file; return file;
} }
public LocalDataset DownloadStreamless(ContentId cid)
{
return CodexAccess.DownloadStreamless(cid);
}
public LocalDataset DownloadManifestOnly(ContentId cid)
{
return CodexAccess.DownloadManifestOnly(cid);
}
public LocalDatasetList LocalFiles() public LocalDatasetList LocalFiles()
{ {
return CodexAccess.LocalFiles(); return CodexAccess.LocalFiles();

View File

@ -18,14 +18,16 @@ namespace CodexReleaseTests.DataTests
var cid = uploader.UploadFile(file); var cid = uploader.UploadFile(file);
var startSpace = downloader.Space(); var startSpace = downloader.Space();
var manifest = downloader.DownloadManifestOnly(cid); var localDataset = downloader.DownloadManifestOnly(cid);
Thread.Sleep(1000); Thread.Sleep(1000);
var spaceDiff = startSpace.FreeBytes - downloader.Space().FreeBytes; var spaceDiff = startSpace.FreeBytes - downloader.Space().FreeBytes;
Assert.That(spaceDiff, Is.LessThan(64.KB().SizeInBytes)); 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));
} }
} }
} }

View File

@ -19,7 +19,10 @@ namespace CodexReleaseTests.DataTests
var startSpace = downloader.Space(); var startSpace = downloader.Space();
var start = DateTime.UtcNow; 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. // TODO: We have no way to inspect the status or progress of the download.
// We use local space information to estimate. // We use local space information to estimate.