Skip to content

Commit

Permalink
feat(csipfs): add "object dump"
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jul 13, 2019
1 parent f1fec34 commit 475596b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
29 changes: 29 additions & 0 deletions IpfsCli/Commands/ObjectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Threading.Tasks;
using Ipfs.Engine.UnixFileSystem;
using System.IO;

namespace Ipfs.Cli
{
[Command(Description = "Manage IPFS objects")]
[Subcommand("links", typeof(ObjectLinksCommand))]
[Subcommand("get", typeof(ObjectGetCommand))]
[Subcommand("dump", typeof(ObjectDumpCommand))]
class ObjectCommand : CommandBase
{
public Program Parent { get; set; }
Expand Down Expand Up @@ -63,4 +66,30 @@ protected override async Task<int> OnExecute(CommandLineApplication app)
}
}

[Command(Description = "Dump the DAG node")]
class ObjectDumpCommand : CommandBase
{
[Argument(0, "cid", "The content ID of the object")]
[Required]
public string Cid { get; set; }

ObjectCommand Parent { get; set; }

class Node
{
public DagNode Dag;
public DataMessage DataMessage;
}

protected override async Task<int> OnExecute(CommandLineApplication app)
{
var Program = Parent.Parent;
var node = new Node();
var block = await Program.CoreApi.Block.GetAsync(Cid);
node.Dag = new DagNode(block.DataStream);
node.DataMessage = ProtoBuf.Serializer.Deserialize<DataMessage>(node.Dag.DataStream);

return Program.Output(app, node, null);
}
}
}
2 changes: 1 addition & 1 deletion IpfsCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static int Main(string[] args)
}

var took = DateTime.Now - startTime;
Console.Write($"Took {took.TotalSeconds} seconds.");
//Console.Write($"Took {took.TotalSeconds} seconds.");

return 0;
}
Expand Down
48 changes: 46 additions & 2 deletions src/UnixFileSystem/DataMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,83 @@

namespace Ipfs.Engine.UnixFileSystem
{
enum DataType
/// <summary>
/// Specifies the type of data.
/// </summary>
public enum DataType
{
/// <summary>
/// Raw data
/// </summary>
Raw = 0,

/// <summary>
/// A directory of files.
/// </summary>
Directory = 1,

/// <summary>
/// A file.
/// </summary>
File = 2,

/// <summary>
/// Metadata (NYI)
/// </summary>
Metadata = 3,

/// <summary>
/// Symbolic link (NYI)
/// </summary>
Symlink = 4,

/// <summary>
/// NYI
/// </summary>
HAMTShard = 5
};

/// <summary>
/// The ProtoBuf data that is stored in a DAG.
/// </summary>
[ProtoContract]
internal class DataMessage
public class DataMessage
{
/// <summary>
/// The type of data.
/// </summary>
[ProtoMember(1, IsRequired = true)]
public DataType Type;

/// <summary>
/// The data.
/// </summary>
[ProtoMember(2, IsRequired = false)]
public byte[] Data;

/// <summary>
/// The file size.
/// </summary>
[ProtoMember(3, IsRequired = false)]
public ulong? FileSize;

/// <summary>
/// The file size of each block.
/// </summary>
[ProtoMember(4, IsRequired = false)]
public ulong[] BlockSizes;

#pragma warning disable 0649 // disable warning about unassinged fields
/// <summary>
/// NYI
/// </summary>
[ProtoMember(5, IsRequired = false)]
public ulong? HashType;

#pragma warning disable 0649 // disable warning about unassinged fields
/// <summary>
/// NYI
/// </summary>
[ProtoMember(6, IsRequired = false)]
public ulong? Fanout;
}
Expand Down

0 comments on commit 475596b

Please sign in to comment.