Skip to content

Commit

Permalink
feat(IFileSystemApi): progress report when adding
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jan 3, 2019
1 parent f9d1583 commit 5283093
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/CoreApi/AddFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@ public class AddFileOptions
/// </remarks>
/// <seealso cref="IKeyApi"/>
public string ProtectionKey { get; set; }

/// <summary>
/// Used to report the progress of a file transfer.
/// </summary>
public IProgress<TransferProgress> Progress { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/CoreApi/TransferProgress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Ipfs.CoreApi
{
/// <summary>
/// Reports the <see cref="IProgress{T}">progress</see> of
/// a transfer operation.
/// </summary>
public class TransferProgress
{
/// <summary>
/// The name of the item being trasfered.
/// </summary>
/// <value>
/// Typically, a relative file path.
/// </value>
public string Name;

/// <summary>
/// The cumuative number of bytes transfered for
/// the <see cref="Name"/>.
/// </summary>
public ulong Bytes;
}
}
7 changes: 6 additions & 1 deletion test/CoreApi/AddFileOptionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -19,6 +20,7 @@ public void Defaults()
Assert.AreEqual(false, options.RawLeaves);
Assert.AreEqual(false, options.Trickle);
Assert.AreEqual(false, options.Wrap);
Assert.IsNull(options.Progress);
}

[TestMethod]
Expand All @@ -31,6 +33,7 @@ public void Setting()
Hash = "sha2-512",
OnlyHash = true,
RawLeaves = true,
Progress = new Progress<TransferProgress>(),
Trickle = true,
Wrap = true
};
Expand All @@ -42,6 +45,8 @@ public void Setting()
Assert.AreEqual(true, options.RawLeaves);
Assert.AreEqual(true, options.Trickle);
Assert.AreEqual(true, options.Wrap);
Assert.IsNotNull(options.Progress);
}

}
}

1 comment on commit 5283093

@richardschneider
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #52

Please sign in to comment.