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);
45  PbDag(Cid const& cid, std::string_view bytes);
46 
47  PbDag(PbDag const&);
48 // PbDag& operator=(PbDag const&) = default;
49 
50  PbDag();
51 
52  ~PbDag() noexcept;
53 
54  bool valid() const;
55 
59  enum class Type {
60  Raw,
61  Directory,
62  File,
63  Metadata,
64  Symlink,
65  HAMTShard,
66  FileChunk,
67  NonFs,
68  Invalid,
69  };
70 
71  Type type() const;
72 
73  bool is_file() const;
74 
75  std::string const& chunk_data() const;
76 
77  std::string const& unparsed() const;
78 
79  Cid const& cid() const;
80 
81  bool cid_matches_data(Client&) const;
82 
84  std::vector<Byte> binary_hash(Client&, HashType = HashType::INVALID) const;
85 
86  void List(std::function<bool(std::string const&, std::string)>) const;
87  std::optional<std::uint64_t> Fanout() const;
88 
89  private:
90  struct Data;
91  std::unique_ptr<Data> pimpl_;
92  bool valid_ = false;
93  bool fs_node_ = false;
94  std::string mime_ = {};
95  std::optional<Cid> cid_ = std::nullopt;
96  std::string original_bytes_;
97 
98  std::string LinkCid(ipfs::ByteView) const;
99 
100 };
101 
102 } // namespace ipfs
103 
104 std::ostream& operator<<(std::ostream&, ipfs::PbDag::Type);
105 
106 #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:59
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