You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/develop/manifests.md
+19-16Lines changed: 19 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,27 +36,29 @@ To work with them, these bytes must be [**unmarshalled** (decoded)](https://en.w
36
36
37
37
`bee-js` provides this functionality through the `MantarayNode.umarshal` method.
38
38
39
-
After unmarshalling, the data is still quite low-level (for example, many fields are `Uint8Array` values) and usually needs additional processing to make it human-readable. You can find a [script for this in the `ethersphere/examples` repo](https://github.com/ethersphere/examples/blob/main/manifests/manifestToJson.js).
39
+
After unmarshalling, the data is still quite low-level (for example, many fields are `Uint8Array` values) and usually needs additional processing to make it human-readable. You can find a [script for this in the `ethersphere/examples` repo](https://github.com/ethersphere/examples/blob/main/manifests/manifestToJson.js).
40
40
:::
41
41
42
42
## Introduction to Manifests
43
43
44
-
Whenever you upload a folder using Bee’s `/bzz` endpoint (and tools built on top of it such as `bee-js` and `swarm-cli`), Bee automatically creates a manifest that records:
44
+
Whenever you upload a folder using Bee’s [`/bzz` endpoint](https://docs.ethswarm.org/api/#tag/BZZ) (and tools built on top of it such as `bee-js` and `swarm-cli`), Bee automatically creates a manifest that records:
Uploads made through the Bee API using `/bytes` or `/chunks`**do not** create manifests.
52
-
However, most developers rarely use these endpoints directly unless they’re building for some custom use-case.
52
+
53
+
However, these endpoints are typically used only for custom use cases requiring lower level control, and are not required for standard use cases such as storing and retrieving files and hosting websites or dapps.
53
54
54
55
Because `bee-js` and `swarm-cli` call `/bzz` when appropriate, **you get a manifest automatically** whenever you upload a directory.
55
56
56
-
:::important
57
+
:::info
57
58
Although working with a manifest may _feel_ like moving or deleting files in a regular filesystem, **no data on Swarm is ever changed**, because all content is immutable.
58
59
59
60
When you "modify" a manifest, you’re actually creating a _new_ manifest based on the previous one.
61
+
60
62
Removing an entry only removes it from the manifest — the underlying file remains available as long as its postage batch is valid.
61
63
:::
62
64
@@ -71,7 +73,7 @@ are also excellent references.
71
73
72
74
## Manifest Structure Explained
73
75
74
-
The printed output below shows a **decoded Mantaray manifest** (printed using the `printManifestJson` method from the [`manifestToJson.js` script in the examples repo](https://github.com/ethersphere/examples/blob/main/manifests/manifestToJson.js)), represented as a tree of nodes and forks. Each part plays a specific role in describing how file paths map to Swarm content. Here’s what each piece means.
76
+
The printed output below shows a **decoded Mantaray manifest** (printed using the `printManifestJson` method from the [`manifestToJson.js` script in the examples repo](https://github.com/ethersphere/examples/blob/main/manifests/manifestToJson.js)), represented as a tree of nodes and forks. Each part plays a specific role in describing how file paths map to Swarm content:
75
77
76
78
```json
77
79
{
@@ -118,6 +120,8 @@ The printed output below shows a **decoded Mantaray manifest** (printed using th
118
120
119
121
```
120
122
123
+
Here’s what each piece means:
124
+
121
125
#### **Node:**
122
126
123
127
A **Node** represents a position within the manifest trie.
@@ -137,7 +141,7 @@ Every node may contain:
137
141
138
142
#### **Forks:**
139
143
140
-
A **fork** is an edge from one node to another.
144
+
A **fork** is an [edge](https://en.wikipedia.org/wiki/Glossary_of_graph_theory#edge) from one node to another.
141
145
It is how the trie branches when file paths diverge.
142
146
143
147
For example, under `folder/`, you see:
@@ -153,7 +157,7 @@ This means:
153
157
- the `folder/` node has two children
154
158
- those children represent different path continuations (i.e., different files)
155
159
156
-
Forks are how shared prefixes are stored only once. Everything that starts with `"folder/"` branches from the same node.
160
+
Forks are how shared prefixes are stored only once. Everything that starts with `folder/` branches from the same node.
157
161
158
162
#### **Path:**
159
163
@@ -193,7 +197,7 @@ For example:
193
197
- The node for `folder/` also has no file associated → target is zero.
194
198
It is just an internal directory-like prefix.
195
199
196
-
Only **leaf nodes**, where a file actually exists, have a non-zero target (the file’s Swarm reference).
200
+
Only [**leaf nodes**](https://en.wikipedia.org/wiki/Glossary_of_graph_theory#leaf) where a file actually exists, have a non-zero target (the file’s Swarm reference).
197
201
198
202
So:
199
203
@@ -205,7 +209,7 @@ So:
205
209
206
210
:::warning
207
211
The `target` field in a manifest points to the raw file root chunk, not a manifest. `bee-js` and `swarm-cli` file download functions expect a file manifest, even for single-file uploads, so downloading using the raw target hash will not work properly.
208
-
Instead, download files by using the top-level directory manifest and the file’s path within it.
212
+
Instead, download files by using the top-level directory root manifest plus the file path relative to the root hash as it is represented in the manifest trie.
209
213
210
214
Example:
211
215
@@ -265,9 +269,9 @@ This means:
265
269
266
270
Meanwhile, `"folder/"` has **no file itself**, so its target is zero.
267
271
268
-
## Manipulating Directories
272
+
## Usage & Example Scripts
269
273
270
-
In this section we explain how to inspect and modify manifests for non-website directories. You can find the completed [example scripts on GitHub](https://github.com/ethersphere/examples/tree/main/manifests).
274
+
In this section we explain how to inspect and modify manifests for non-website directories. You can find the completed [example scripts on GitHub](https://github.com/ethersphere/examples/tree/main/manifests/directory).
271
275
272
276
In the following guides we will explain how to:
273
277
@@ -326,7 +330,7 @@ POSTAGE_BATCH_ID=<BATCH_ID>
326
330
327
331
Great! Now you're all set up and ready to go.
328
332
329
-
### Uploading a Directory and Printing Its Manifest
333
+
### Uploading and Printing
330
334
331
335
In our first script, we will simply upload our sample directory and print its contents:
We will use this in the next section when adding a file manually to the manifest.
466
470
467
-
### Adding a New File to the Manifest
471
+
### Adding a New File
468
472
469
473
This script uploads a **new file** (e.g. `newfile.txt`) and then updates the existing manifest so the new file becomes part of the directory structure.
470
474
@@ -589,7 +593,7 @@ new.txt: Hi, I'm new here.
589
593
590
594
This produces a new manifest where `/new.txt` is now accessible as a root level entry.
591
595
592
-
### Moving a File to a Subfolder
596
+
### Moving a File
593
597
594
598
This script:
595
599
@@ -738,4 +742,3 @@ Now the file appears under:
738
742
739
743
Note that the only new method we used was `node.removeFork()` to remove the entry from the manifest.
0 commit comments