ipfs-chromium
pb_dag.h
1 #ifndef IPFS_PB_DAG_H_
2 #define IPFS_PB_DAG_H_
3 
4 #include "cid.h"
5 
6 #include <vocab/byte_view.h>
7 
8 #include <functional>
9 #include <iosfwd>
10 #include <memory>
11 #include <optional>
12 
13 namespace ipfs {
14 
15 class Client;
16 
24 class PbDag {
25  public:
31  PbDag(Cid const& cid, std::istream& stream);
32 
40  PbDag(Cid const& cid, ByteView bytes);
41  PbDag(Cid const& cid, std::string_view bytes);
42 
43  PbDag(PbDag const&);
44 // PbDag& operator=(PbDag const&) = default;
45 
46  PbDag();
47 
48  ~PbDag() noexcept;
49 
50  bool valid() const;
51 
55  enum class Type {
56  Raw,
57  Directory,
58  File,
59  Metadata,
60  Symlink,
61  HAMTShard,
62  FileChunk,
63  NonFs,
64  Invalid,
65  };
66 
67  Type type() const;
68 
69  bool is_file() const;
70 
71  std::string const& chunk_data() const;
72 
73  std::string const& unparsed() const;
74 
75  Cid const& cid() const;
76 
77  bool cid_matches_data(Client&) const;
78 
80  std::vector<Byte> binary_hash(Client&, HashType = HashType::INVALID) const;
81 
82  void List(std::function<bool(std::string const&, std::string)>) const;
83  std::optional<std::uint64_t> Fanout() const;
84 
85  private:
86  struct Data;
87  std::unique_ptr<Data> pimpl_;
88  bool valid_ = false;
89  bool fs_node_ = false;
90  std::string mime_ = {};
91  std::optional<Cid> cid_ = std::nullopt;
92  std::string original_bytes_;
93 
94  std::string LinkCid(ipfs::ByteView) const;
95 
96 };
97 
98 } // namespace ipfs
99 
100 std::ostream& operator<<(std::ostream&, ipfs::PbDag::Type);
101 
102 #endif // IPFS_PB_DAG_H_
Definition: cid.h:16
Interface that provides functionality from whatever environment you're using this library in.
Definition: client.h:42
Something to which a CID may refer directly.
Definition: pb_dag.h:24
std::vector< Byte > binary_hash(Client &, HashType=HashType::INVALID) const
Pass INVALID to mean cid().hash_type()
Definition: pb_dag.cc:191
Cid const & cid() const
Getter for Content IDentifier.
Definition: pb_dag.cc:154
PbDag()
Construct an invalid block.
Type
The kinds of things a block may be representing.
Definition: pb_dag.h:55
std::string const & unparsed() const
Original bytes (with protobuf bits)
Definition: pb_dag.cc:150
bool valid() const
Check if the block appears valid.
Definition: pb_dag.cc:117
Type type() const
Accessor for this block's type.
Definition: pb_dag.cc:121
std::string const & chunk_data() const
data field from a UnixFS node
Definition: pb_dag.cc:146
bool is_file() const
type() == File || type() == FileChunk
Definition: pb_dag.cc:141
bool cid_matches_data(Client &) const
Basic validation.
Definition: pb_dag.cc:173