public async Task <string> AddFileAsync(string filePath, bool pin, DownloadProgressDelegate progressCallBack) { using (var fileStream = new FileStreamWithProgress(filePath, FileMode.Open, FileAccess.Read)) { fileStream.SetTotalLength(fileStream.Length); fileStream.SetCaption("upload progress"); fileStream.ProgressCallBack += progressCallBack; var task = await Ipfs.FileSystem.AddAsync(fileStream, Path.GetFileName(filePath), new AddFileOptions { Pin = pin, Wrap = true }); fileStream.ProgressCallBack = null; return(task.Id.Hash.ToString()); } }
public async Task DownloadFileAsync(string ipfsPath, string path, long fileSize, bool pin, DownloadProgressDelegate progressCallBack) { // using (var stream = await Ipfs.DownloadAsync("object/get", default(CancellationToken), ipfsPath)) using (var stream = await Ipfs.FileSystem.ReadFileAsync(ipfsPath)) { using (var fileStream = new FileStreamWithProgress(path, FileMode.Create))//File.Create(path)) { fileStream.SetTotalLength(fileSize); fileStream.ProgressCallBack += progressCallBack; stream.CopyTo(fileStream); fileStream.ProgressCallBack = null; if (pin) { await Ipfs.Pin.AddAsync(ipfsPath); } } } }