Skip to content

Commit 9d6c7cb

Browse files
dependabot[bot]achingbrain
andauthoredJan 19, 2024
deps(dev): bump aegir from 41.3.5 to 42.2.2 (#399)
Bumps [aegir](https://github.com/ipfs/aegir) from 41.3.5 to 42.2.2. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](ipfs/aegir@v41.3.5...v42.2.2) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain <[email protected]>
1 parent 6901826 commit 9d6c7cb

File tree

21 files changed

+608
-684
lines changed

21 files changed

+608
-684
lines changed
 

‎.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ updates:
55
schedule:
66
interval: daily
77
time: "10:00"
8-
open-pull-requests-limit: 10
8+
open-pull-requests-limit: 20
99
commit-message:
1010
prefix: "deps"
1111
prefix-development: "deps(dev)"

‎.github/workflows/js-test-and-release.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ on:
99

1010
permissions:
1111
contents: write
12+
id-token: write
1213
packages: write
14+
pull-requests: write
1315

1416
concurrency:
1517
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Semantic PR
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3

‎.npmrc

-2
This file was deleted.

‎README.md

+5-48
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,30 @@
1-
# js-ipfs-unixfs <!-- omit in toc -->
2-
31
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
42
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
53
[![codecov](https://img.shields.io/codecov/c/github/ipfs/js-ipfs-unixfs.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-unixfs)
64
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/js-ipfs-unixfs/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/ipfs/js-ipfs-unixfs/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
75

86
> JS implementation of the IPFS UnixFS
97
10-
## Table of contents <!-- omit in toc -->
11-
12-
- [Structure](#structure)
13-
- [Lead Maintainer <!-- omit in toc -->](#lead-maintainer----omit-in-toc---)
14-
- [Development](#development)
15-
- [Publishing new versions](#publishing-new-versions)
16-
- [Using prerelease versions](#using-prerelease-versions)
17-
- [API Docs](#api-docs)
18-
- [License](#license)
19-
- [Contribute](#contribute)
8+
The UnixFS spec can be found at [ipfs/specs/UNIXFS.md](https://github.com/ipfs/specs/blob/master/UNIXFS.md)
209

21-
## Structure
10+
# Packages
2211

2312
- [`/packages/ipfs-unixfs`](./packages/ipfs-unixfs) JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
2413
- [`/packages/ipfs-unixfs-exporter`](./packages/ipfs-unixfs-exporter) JavaScript implementation of the UnixFs exporter used by IPFS
2514
- [`/packages/ipfs-unixfs-importer`](./packages/ipfs-unixfs-importer) JavaScript implementation of the UnixFs importer used by IPFS
2615

27-
The UnixFS spec can be found at [ipfs/specs/UNIXFS.md](https://github.com/ipfs/specs/blob/master/UNIXFS.md)
28-
29-
## Lead Maintainer <!-- omit in toc -->
30-
31-
[Alex Potsides](https://github.com/achingbrain)
32-
33-
- [`/packages/ipfs-unixfs`](./packages/ipfs-unixfs) Serialization/deserialization of UnixFS objects to protocol buffers
34-
- [`/packages/ipfs-unixfs-importer`](./packages/ipfs-unixfs-importer) Builds DAGs from files and directories
35-
- [`/packages/ipfs-unixfs-exporter`](./packages/ipfs-unixfs-exporter) Exports DAGs
36-
37-
## Development
38-
39-
1. Clone this repo
40-
2. Run `npm install`
41-
42-
This will install [lerna](https://www.npmjs.com/package/lerna) and bootstrap the various packages, dedpuing and hoisting dependencies into the root folder.
43-
44-
If later you wish to remove all the `node_modules`/`dist` folders and start again, run `npm run reset && npm install` from the root.
45-
46-
See the scripts section of the root [`package.json`](./package.json) for more commands.
47-
48-
### Publishing new versions
49-
50-
1. Ensure you have a `GH_TOKEN` env var containing a GitHub [Personal Access Token](https://github.com/settings/tokens) with `public_repo` permissions
51-
2. From the root of this repo run `npm run release` and follow the on screen prompts. It will use [conventional commits](https://www.conventionalcommits.org) to work out the new package version
52-
53-
### Using prerelease versions
54-
55-
Any changed packages from each successful build of master are published to npm as canary builds under the npm tag `next`.
56-
57-
Canary builds only consider changes to packages in the last built commit so changes to the root config files should not result in new prereleases being published to npm.
58-
59-
## API Docs
16+
# API Docs
6017

6118
- <https://ipfs.github.io/js-ipfs-unixfs>
6219

63-
## License
20+
# License
6421

6522
Licensed under either of
6623

6724
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
6825
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
6926

70-
## Contribute
27+
# Contribute
7128

7229
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs-unixfs/issues).
7330

‎package.json

+87-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
"bugs": {
1212
"url": "https://github.com/ipfs/js-ipfs-unixfs/issues"
1313
},
14-
"engines": {
15-
"node": ">=16.0.0",
16-
"npm": ">=7.0.0"
17-
},
1814
"private": true,
1915
"scripts": {
2016
"reset": "aegir run clean && aegir clean ./node_modules ./package-lock.json packages/*/node_modules packages/*/package-lock.json",
@@ -36,9 +32,94 @@
3632
"release": "npm run docs:no-publish && aegir run release && npm run docs"
3733
},
3834
"devDependencies": {
39-
"aegir": "^41.3.2"
35+
"aegir": "^42.2.2"
4036
},
4137
"workspaces": [
4238
"packages/*"
43-
]
39+
],
40+
"release": {
41+
"branches": [
42+
"main"
43+
],
44+
"plugins": [
45+
[
46+
"@semantic-release/commit-analyzer",
47+
{
48+
"preset": "conventionalcommits",
49+
"releaseRules": [
50+
{
51+
"breaking": true,
52+
"release": "major"
53+
},
54+
{
55+
"revert": true,
56+
"release": "patch"
57+
},
58+
{
59+
"type": "feat",
60+
"release": "minor"
61+
},
62+
{
63+
"type": "fix",
64+
"release": "patch"
65+
},
66+
{
67+
"type": "docs",
68+
"release": "patch"
69+
},
70+
{
71+
"type": "test",
72+
"release": "patch"
73+
},
74+
{
75+
"type": "deps",
76+
"release": "patch"
77+
},
78+
{
79+
"scope": "no-release",
80+
"release": false
81+
}
82+
]
83+
}
84+
],
85+
[
86+
"@semantic-release/release-notes-generator",
87+
{
88+
"preset": "conventionalcommits",
89+
"presetConfig": {
90+
"types": [
91+
{
92+
"type": "feat",
93+
"section": "Features"
94+
},
95+
{
96+
"type": "fix",
97+
"section": "Bug Fixes"
98+
},
99+
{
100+
"type": "chore",
101+
"section": "Trivial Changes"
102+
},
103+
{
104+
"type": "docs",
105+
"section": "Documentation"
106+
},
107+
{
108+
"type": "deps",
109+
"section": "Dependencies"
110+
},
111+
{
112+
"type": "test",
113+
"section": "Tests"
114+
}
115+
]
116+
}
117+
}
118+
],
119+
"@semantic-release/changelog",
120+
"@semantic-release/npm",
121+
"@semantic-release/github",
122+
"@semantic-release/git"
123+
]
124+
}
44125
}

‎packages/ipfs-unixfs-exporter/README.md

+12-182
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,9 @@
77

88
> JavaScript implementation of the UnixFs exporter used by IPFS
99
10-
## Table of contents <!-- omit in toc -->
11-
12-
- [Install](#install)
13-
- [Browser `<script>` tag](#browser-script-tag)
14-
- [Example](#example)
15-
- [API](#api)
16-
- [`exporter(cid, blockstore, options)`](#exportercid-blockstore-options)
17-
- [UnixFSEntry](#unixfsentry)
18-
- [Raw entries](#raw-entries)
19-
- [CBOR entries](#cbor-entries)
20-
- [`entry.content({ offset, length })`](#entrycontent-offset-length-)
21-
- [`walkPath(cid, blockstore)`](#walkpathcid-blockstore)
22-
- [`recursive(cid, blockstore)`](#recursivecid-blockstore)
23-
- [API Docs](#api-docs)
24-
- [License](#license)
25-
- [Contribute](#contribute)
26-
27-
## Install
10+
# About
2811

29-
```console
30-
$ npm i ipfs-unixfs-exporter
31-
```
32-
33-
### Browser `<script>` tag
34-
35-
Loading this module through a script tag will make it's exports available as `IpfsUnixfsExporter` in the global namespace.
36-
37-
```html
38-
<script src="https://unpkg.com/ipfs-unixfs-exporter/dist/index.min.js"></script>
39-
```
12+
The UnixFS Exporter provides a means to read DAGs from a blockstore given a CID.
4013

4114
## Example
4215

@@ -79,175 +52,32 @@ for await (const buf of entry.content()) {
7952
console.info(bytes) // 0, 1, 2, 3
8053
```
8154

82-
## API
83-
84-
```js
85-
import { exporter } from 'ipfs-unixfs-exporter'
86-
```
87-
88-
### `exporter(cid, blockstore, options)`
89-
90-
Uses the given [blockstore][] instance to fetch an IPFS node by it's CID.
91-
92-
Returns a Promise which resolves to a `UnixFSEntry`.
93-
94-
`options` is an optional object argument that might include the following keys:
95-
96-
- `signal` ([AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)): Used to cancel any network requests that are initiated as a result of this export
97-
98-
### UnixFSEntry
55+
# Install
9956

100-
```javascript
101-
{
102-
type: 'file' // or 'directory'
103-
name: 'foo.txt',
104-
path: 'Qmbar/foo.txt',
105-
cid: CID, // see https://github.com/multiformats/js-cid
106-
content: function, // returns an async iterator
107-
unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
108-
}
109-
```
110-
111-
If the entry is a file, `entry.content()` returns an async iterator that yields one or more Uint8Arrays containing the file content:
112-
113-
```javascript
114-
if (entry.type === 'file') {
115-
for await (const chunk of entry.content()) {
116-
// chunk is a Buffer
117-
}
118-
}
119-
```
120-
121-
If the entry is a directory, `entry.content()` returns further `entry` objects:
122-
123-
```javascript
124-
if (entry.type === 'directory') {
125-
for await (const entry of dir.content()) {
126-
console.info(entry.name)
127-
}
128-
}
129-
```
130-
131-
### Raw entries
132-
133-
Entries with a `raw` codec `CID` return raw entries:
134-
135-
```javascript
136-
{
137-
name: 'foo.txt',
138-
path: 'Qmbar/foo.txt',
139-
cid: CID, // see https://github.com/multiformats/js-cid
140-
node: Buffer, // see https://nodejs.org/api/buffer.html
141-
content: function, // returns an async iterator
142-
}
143-
```
144-
145-
`entry.content()` returns an async iterator that yields a buffer containing the node content:
146-
147-
```javascript
148-
for await (const chunk of entry.content()) {
149-
// chunk is a Buffer
150-
}
151-
```
152-
153-
Unless you an options object containing `offset` and `length` keys as an argument to `entry.content()`, `chunk` will be equal to `entry.node`.
154-
155-
### CBOR entries
156-
157-
Entries with a `dag-cbor` codec `CID` return JavaScript object entries:
158-
159-
```javascript
160-
{
161-
name: 'foo.txt',
162-
path: 'Qmbar/foo.txt',
163-
cid: CID, // see https://github.com/multiformats/js-cid
164-
node: Uint8Array,
165-
content: function // returns an async iterator that yields a single object - see https://github.com/ipld/js-ipld-dag-cbor
166-
}
167-
```
168-
169-
There is no `content` function for a `CBOR` node.
170-
171-
### `entry.content({ offset, length })`
172-
173-
When `entry` is a file or a `raw` node, `offset` and/or `length` arguments can be passed to `entry.content()` to return slices of data:
174-
175-
```javascript
176-
const length = 5
177-
const data = new Uint8Array(length)
178-
let offset = 0
179-
180-
for await (const chunk of entry.content({
181-
offset: 0,
182-
length
183-
})) {
184-
data.set(chunk, offset)
185-
offset += chunk.length
186-
}
187-
188-
// `data` contains the first 5 bytes of the file
189-
return data
190-
```
191-
192-
If `entry` is a directory, passing `offset` and/or `length` to `entry.content()` will limit the number of files returned from the directory.
193-
194-
```javascript
195-
const entries = []
196-
197-
for await (const entry of dir.content({
198-
offset: 0,
199-
length: 5
200-
})) {
201-
entries.push(entry)
202-
}
203-
204-
// `entries` contains the first 5 files/directories in the directory
205-
```
206-
207-
### `walkPath(cid, blockstore)`
208-
209-
`walkPath` will return an async iterator that yields entries for all segments in a path:
210-
211-
```javascript
212-
import { walkPath } from 'ipfs-unixfs-exporter'
213-
214-
const entries = []
215-
216-
for await (const entry of walkPath('Qmfoo/foo/bar/baz.txt', blockstore)) {
217-
entries.push(entry)
218-
}
219-
220-
// entries contains 4x `entry` objects
57+
```console
58+
$ npm i ipfs-unixfs-exporter
22159
```
22260

223-
### `recursive(cid, blockstore)`
224-
225-
`recursive` will return an async iterator that yields all entries beneath a given CID or IPFS path, as well as the containing directory.
226-
227-
```javascript
228-
import { recursive } from 'ipfs-unixfs-exporter'
229-
230-
const entries = []
61+
## Browser `<script>` tag
23162

232-
for await (const child of recursive('Qmfoo/foo/bar', blockstore)) {
233-
entries.push(entry)
234-
}
63+
Loading this module through a script tag will make it's exports available as `IpfsUnixfsExporter` in the global namespace.
23564

236-
// entries contains all children of the `Qmfoo/foo/bar` directory and it's children
65+
```html
66+
<script src="https://unpkg.com/ipfs-unixfs-exporter/dist/index.min.js"></script>
23767
```
23868

239-
## API Docs
69+
# API Docs
24070

24171
- <https://ipfs.github.io/js-ipfs-unixfs/modules/ipfs_unixfs_exporter.html>
24272

243-
## License
73+
# License
24474

24575
Licensed under either of
24676

24777
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
24878
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
24979

250-
## Contribute
80+
# Contribute
25181

25282
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs-unixfs/issues).
25383

‎packages/ipfs-unixfs-exporter/package.json

+8-95
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"bugs": {
1212
"url": "https://github.com/ipfs/js-ipfs-unixfs/issues"
1313
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
1418
"keywords": [
1519
"IPFS"
1620
],
17-
"engines": {
18-
"node": ">=16.0.0",
19-
"npm": ">=7.0.0"
20-
},
2121
"type": "module",
2222
"types": "./dist/src/index.d.ts",
2323
"files": [
@@ -35,94 +35,10 @@
3535
"eslintConfig": {
3636
"extends": "ipfs",
3737
"parserOptions": {
38+
"project": true,
3839
"sourceType": "module"
3940
}
4041
},
41-
"release": {
42-
"branches": [
43-
"master"
44-
],
45-
"plugins": [
46-
[
47-
"@semantic-release/commit-analyzer",
48-
{
49-
"preset": "conventionalcommits",
50-
"releaseRules": [
51-
{
52-
"breaking": true,
53-
"release": "major"
54-
},
55-
{
56-
"revert": true,
57-
"release": "patch"
58-
},
59-
{
60-
"type": "feat",
61-
"release": "minor"
62-
},
63-
{
64-
"type": "fix",
65-
"release": "patch"
66-
},
67-
{
68-
"type": "docs",
69-
"release": "patch"
70-
},
71-
{
72-
"type": "test",
73-
"release": "patch"
74-
},
75-
{
76-
"type": "deps",
77-
"release": "patch"
78-
},
79-
{
80-
"scope": "no-release",
81-
"release": false
82-
}
83-
]
84-
}
85-
],
86-
[
87-
"@semantic-release/release-notes-generator",
88-
{
89-
"preset": "conventionalcommits",
90-
"presetConfig": {
91-
"types": [
92-
{
93-
"type": "feat",
94-
"section": "Features"
95-
},
96-
{
97-
"type": "fix",
98-
"section": "Bug Fixes"
99-
},
100-
{
101-
"type": "chore",
102-
"section": "Trivial Changes"
103-
},
104-
{
105-
"type": "docs",
106-
"section": "Documentation"
107-
},
108-
{
109-
"type": "deps",
110-
"section": "Dependencies"
111-
},
112-
{
113-
"type": "test",
114-
"section": "Tests"
115-
}
116-
]
117-
}
118-
}
119-
],
120-
"@semantic-release/changelog",
121-
"@semantic-release/npm",
122-
"@semantic-release/github",
123-
"@semantic-release/git"
124-
]
125-
},
12642
"scripts": {
12743
"test": "aegir test",
12844
"test:node": "aegir test -t node --cov",
@@ -151,13 +67,12 @@
15167
"it-pushable": "^3.1.0",
15268
"multiformats": "^13.0.0",
15369
"p-queue": "^8.0.1",
154-
"progress-events": "^1.0.0",
155-
"uint8arrays": "^5.0.0"
70+
"progress-events": "^1.0.0"
15671
},
15772
"devDependencies": {
15873
"@types/readable-stream": "^4.0.1",
15974
"@types/sinon": "^17.0.2",
160-
"aegir": "^41.3.2",
75+
"aegir": "^42.2.2",
16176
"blockstore-core": "^4.0.1",
16277
"delay": "^6.0.0",
16378
"ipfs-unixfs-importer": "^15.0.0",
@@ -169,13 +84,11 @@
16984
"merge-options": "^3.0.4",
17085
"readable-stream": "^4.4.0",
17186
"sinon": "^17.0.1",
87+
"uint8arrays": "^5.0.0",
17288
"wherearewe": "^2.0.1"
17389
},
17490
"browser": {
17591
"fs": false,
17692
"readable-stream": false
177-
},
178-
"typedoc": {
179-
"entryPoint": "./src/index.ts"
18093
}
18194
}

‎packages/ipfs-unixfs-exporter/src/index.ts

+230
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
/**
2+
* @packageDocumentation
3+
*
4+
* The UnixFS Exporter provides a means to read DAGs from a blockstore given a CID.
5+
*
6+
* @example
7+
*
8+
* ```js
9+
* // import a file and export it again
10+
* import { importer } from 'ipfs-unixfs-importer'
11+
* import { exporter } from 'ipfs-unixfs-exporter'
12+
* import { MemoryBlockstore } from 'blockstore-core/memory'
13+
*
14+
* // Should contain the blocks we are trying to export
15+
* const blockstore = new MemoryBlockstore()
16+
* const files = []
17+
*
18+
* for await (const file of importer([{
19+
* path: '/foo/bar.txt',
20+
* content: new Uint8Array([0, 1, 2, 3])
21+
* }], blockstore)) {
22+
* files.push(file)
23+
* }
24+
*
25+
* console.info(files[0].cid) // Qmbaz
26+
*
27+
* const entry = await exporter(files[0].cid, blockstore)
28+
*
29+
* console.info(entry.cid) // Qmqux
30+
* console.info(entry.path) // Qmbaz/foo/bar.txt
31+
* console.info(entry.name) // bar.txt
32+
* console.info(entry.unixfs.fileSize()) // 4
33+
*
34+
* // stream content from unixfs node
35+
* const size = entry.unixfs.fileSize()
36+
* const bytes = new Uint8Array(size)
37+
* let offset = 0
38+
*
39+
* for await (const buf of entry.content()) {
40+
* bytes.set(buf, offset)
41+
* offset += chunk.length
42+
* }
43+
*
44+
* console.info(bytes) // 0, 1, 2, 3
45+
* ```
46+
*/
47+
148
import errCode from 'err-code'
249
import last from 'it-last'
350
import { CID } from 'multiformats/cid'
@@ -53,42 +100,162 @@ export interface ExporterOptions extends ProgressOptions<ExporterProgressEvents>
53100
}
54101

55102
export interface Exportable<T> {
103+
/**
104+
* A disambiguator to allow TypeScript to work out the type of the entry.
105+
*
106+
* @example
107+
*
108+
* ```TypeScript
109+
* if (entry.type === 'file') {
110+
* // access UnixFSFile properties safely
111+
* }
112+
*
113+
* if (entry.type === 'directory') {
114+
* // access UnixFSDirectory properties safely
115+
* }
116+
* ```
117+
*/
56118
type: 'file' | 'directory' | 'object' | 'raw' | 'identity'
119+
120+
/**
121+
* The name of the entry
122+
*/
57123
name: string
124+
125+
/**
126+
* The path of the entry within the DAG in which it was encountered
127+
*/
58128
path: string
129+
130+
/**
131+
* The CID of the entry
132+
*/
59133
cid: CID
134+
135+
/**
136+
* How far down the DAG the entry is
137+
*/
60138
depth: number
139+
140+
/**
141+
* The size of the entry
142+
*/
61143
size: bigint
144+
145+
/**
146+
* When `entry` is a file or a `raw` node, `offset` and/or `length` arguments can be passed to `entry.content()` to return slices of data:
147+
*
148+
* ```javascript
149+
* const length = 5
150+
* const data = new Uint8Array(length)
151+
* let offset = 0
152+
*
153+
* for await (const chunk of entry.content({
154+
* offset: 0,
155+
* length
156+
* })) {
157+
* data.set(chunk, offset)
158+
* offset += chunk.length
159+
* }
160+
*
161+
* // `data` contains the first 5 bytes of the file
162+
* return data
163+
* ```
164+
*
165+
* If `entry` is a directory, passing `offset` and/or `length` to `entry.content()` will limit the number of files returned from the directory.
166+
*
167+
* ```javascript
168+
* const entries = []
169+
*
170+
* for await (const entry of dir.content({
171+
* offset: 0,
172+
* length: 5
173+
* })) {
174+
* entries.push(entry)
175+
* }
176+
*
177+
* // `entries` contains the first 5 files/directories in the directory
178+
* ```
179+
*
180+
*/
62181
content(options?: ExporterOptions): AsyncGenerator<T, void, unknown>
63182
}
64183

184+
/**
185+
* If the entry is a file, `entry.content()` returns an async iterator that yields one or more Uint8Arrays containing the file content:
186+
*
187+
* ```javascript
188+
* if (entry.type === 'file') {
189+
* for await (const chunk of entry.content()) {
190+
* // chunk is a Buffer
191+
* }
192+
* }
193+
* ```
194+
*/
65195
export interface UnixFSFile extends Exportable<Uint8Array> {
66196
type: 'file'
67197
unixfs: UnixFS
68198
node: PBNode
69199
}
70200

201+
/**
202+
* If the entry is a directory, `entry.content()` returns further `entry` objects:
203+
*
204+
* ```javascript
205+
* if (entry.type === 'directory') {
206+
* for await (const entry of dir.content()) {
207+
* console.info(entry.name)
208+
* }
209+
* }
210+
* ```
211+
*/
71212
export interface UnixFSDirectory extends Exportable<UnixFSEntry> {
72213
type: 'directory'
73214
unixfs: UnixFS
74215
node: PBNode
75216
}
76217

218+
/**
219+
* Entries with a `dag-cbor` or `dag-json` codec {@link CID} return JavaScript object entries
220+
*/
77221
export interface ObjectNode extends Exportable<any> {
78222
type: 'object'
79223
node: Uint8Array
80224
}
81225

226+
/**
227+
* Entries with a `raw` codec {@link CID} return raw entries.
228+
*
229+
* `entry.content()` returns an async iterator that yields a buffer containing the node content:
230+
*
231+
* ```javascript
232+
* for await (const chunk of entry.content()) {
233+
* // chunk is a Buffer
234+
* }
235+
* ```
236+
*
237+
* Unless you an options object containing `offset` and `length` keys as an argument to `entry.content()`, `chunk` will be equal to `entry.node`.
238+
*/
82239
export interface RawNode extends Exportable<Uint8Array> {
83240
type: 'raw'
84241
node: Uint8Array
85242
}
86243

244+
/**
245+
* Entries with a `identity` codec {@link CID} return identity entries.
246+
*
247+
* These are entries where the data payload is stored in the CID itself,
248+
* otherwise they are identical to {@link RawNode}s.
249+
*/
87250
export interface IdentityNode extends Exportable<Uint8Array> {
88251
type: 'identity'
89252
node: Uint8Array
90253
}
91254

255+
/**
256+
* A UnixFSEntry is a representation of the types of node that can be
257+
* encountered in a DAG.
258+
*/
92259
export type UnixFSEntry = UnixFSFile | UnixFSDirectory | ObjectNode | RawNode | IdentityNode
93260

94261
export interface NextResult {
@@ -117,6 +284,10 @@ export interface ShardTraversalContext {
117284
lastBucket: Bucket<boolean>
118285
}
119286

287+
/**
288+
* A subset of the {@link Blockstore} interface that just contains the get
289+
* method.
290+
*/
120291
export type ReadableStorage = Pick<Blockstore, 'get'>
121292

122293
const toPathComponents = (path: string = ''): string[] => {
@@ -159,6 +330,23 @@ const cidAndRest = (path: string | Uint8Array | CID): { cid: CID, toResolve: str
159330
throw errCode(new Error(`Unknown path type ${path}`), 'ERR_BAD_PATH')
160331
}
161332

333+
/**
334+
* Returns an async iterator that yields entries for all segments in a path
335+
*
336+
* @example
337+
*
338+
* ```javascript
339+
* import { walkPath } from 'ipfs-unixfs-exporter'
340+
*
341+
* const entries = []
342+
*
343+
* for await (const entry of walkPath('Qmfoo/foo/bar/baz.txt', blockstore)) {
344+
* entries.push(entry)
345+
* }
346+
*
347+
* // entries contains 4x `entry` objects
348+
* ```
349+
*/
162350
export async function * walkPath (path: string | CID, blockstore: ReadableStorage, options: ExporterOptions = {}): AsyncGenerator<UnixFSEntry, void, any> {
163351
let {
164352
cid,
@@ -191,6 +379,30 @@ export async function * walkPath (path: string | CID, blockstore: ReadableStorag
191379
}
192380
}
193381

382+
/**
383+
* Uses the given blockstore instance to fetch an IPFS node by a CID or path.
384+
*
385+
* Returns a {@link Promise} which resolves to a {@link UnixFSEntry}.
386+
*
387+
* @example
388+
*
389+
* ```typescript
390+
* import { exporter } from 'ipfs-unixfs-exporter'
391+
* import { CID } from 'multiformats/cid'
392+
*
393+
* const cid = CID.parse('QmFoo')
394+
*
395+
* const entry = await exporter(cid, blockstore, {
396+
* signal: AbortSignal.timeout(50000)
397+
* })
398+
*
399+
* if (entry.type === 'file') {
400+
* for await (const chunk of entry.content()) {
401+
* // chunk is a Uint8Array
402+
* }
403+
* }
404+
* ```
405+
*/
194406
export async function exporter (path: string | CID, blockstore: ReadableStorage, options: ExporterOptions = {}): Promise<UnixFSEntry> {
195407
const result = await last(walkPath(path, blockstore, options))
196408

@@ -201,6 +413,24 @@ export async function exporter (path: string | CID, blockstore: ReadableStorage,
201413
return result
202414
}
203415

416+
/**
417+
* Returns an async iterator that yields all entries beneath a given CID or IPFS
418+
* path, as well as the containing directory.
419+
*
420+
* @example
421+
*
422+
* ```typescript
423+
* import { recursive } from 'ipfs-unixfs-exporter'
424+
*
425+
* const entries = []
426+
*
427+
* for await (const child of recursive('Qmfoo/foo/bar', blockstore)) {
428+
* entries.push(entry)
429+
* }
430+
*
431+
* // entries contains all children of the `Qmfoo/foo/bar` directory and it's children
432+
* ```
433+
*/
204434
export async function * recursive (path: string | CID, blockstore: ReadableStorage, options: ExporterOptions = {}): AsyncGenerator<UnixFSEntry, void, any> {
205435
const node = await exporter(path, blockstore, options)
206436

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"entryPoints": [
3+
"./src/index.ts"
4+
],
5+
"readme": "none"
6+
}

‎packages/ipfs-unixfs-importer/README.md

+12-66
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,13 @@
77

88
> JavaScript implementation of the UnixFs importer used by IPFS
99
10-
## Table of contents <!-- omit in toc -->
11-
12-
- [Install](#install)
13-
- [Browser `<script>` tag](#browser-script-tag)
14-
- [Example](#example)
15-
- [API](#api)
16-
- [const stream = importer(source, blockstore \[, options\])](#const-stream--importersource-blockstore--options)
17-
- [const result = await importFile(content, blockstore \[, options\])](#const-result--await-importfilecontent-blockstore--options)
18-
- [const result = await importDirectory(content, blockstore \[, options\])](#const-result--await-importdirectorycontent-blockstore--options)
19-
- [const result = await importBytes(buf, blockstore \[, options\])](#const-result--await-importbytesbuf-blockstore--options)
20-
- [const result = await importByteStream(source, blockstore \[, options\])](#const-result--await-importbytestreamsource-blockstore--options)
21-
- [API Docs](#api-docs)
22-
- [License](#license)
23-
- [Contribute](#contribute)
24-
25-
## Install
26-
27-
```console
28-
$ npm i ipfs-unixfs-importer
29-
```
30-
31-
### Browser `<script>` tag
32-
33-
Loading this module through a script tag will make it's exports available as `IpfsUnixfsImporter` in the global namespace.
34-
35-
```html
36-
<script src="https://unpkg.com/ipfs-unixfs-importer/dist/index.min.js"></script>
37-
```
10+
# About
3811

3912
## Example
4013

4114
Let's create a little directory to import:
4215

43-
```sh
16+
```console
4417
> cd /tmp
4518
> mkdir foo
4619
> echo 'hello' > foo/bar
@@ -96,59 +69,32 @@ When run, metadata about DAGNodes in the created tree is printed until the root:
9669
}
9770
```
9871

99-
## API
72+
# Install
10073

101-
```js
102-
import { importer, importFile, importDir, importBytes, importByteStream } from 'ipfs-unixfs-importer'
74+
```console
75+
$ npm i ipfs-unixfs-importer
10376
```
10477

105-
### const stream = importer(source, blockstore \[, options])
78+
## Browser `<script>` tag
10679

107-
The `importer` function returns an async iterator takes a source async iterator that yields objects of the form:
80+
Loading this module through a script tag will make it's exports available as `IpfsUnixfsImporter` in the global namespace.
10881

109-
```js
110-
{
111-
path: 'a name',
112-
content: (Buffer or iterator emitting Buffers),
113-
mtime: (Number representing seconds since (positive) or before (negative) the Unix Epoch),
114-
mode: (Number representing ugo-rwx, setuid, setguid and sticky bit)
115-
}
82+
```html
83+
<script src="https://unpkg.com/ipfs-unixfs-importer/dist/index.min.js"></script>
11684
```
11785

118-
`stream` will output file info objects as files get stored in IPFS. When stats on a node are emitted they are guaranteed to have been written.
119-
120-
`blockstore` is an instance of a [blockstore][]
121-
122-
The input's file paths and directory structure will be preserved in the [`dag-pb`](https://github.com/ipld/js-dag-pb) created nodes.
123-
124-
### const result = await importFile(content, blockstore \[, options])
125-
126-
A convenience function for importing a single file or directory.
127-
128-
### const result = await importDirectory(content, blockstore \[, options])
129-
130-
A convenience function for importing a directory - note this is non-recursive, to import recursively use the [importer](#const-stream--importersource-blockstore--options) function.
131-
132-
### const result = await importBytes(buf, blockstore \[, options])
133-
134-
A convenience function for importing a single Uint8Array.
135-
136-
### const result = await importByteStream(source, blockstore \[, options])
137-
138-
A convenience function for importing a single stream of Uint8Arrays.
139-
140-
## API Docs
86+
# API Docs
14187

14288
- <https://ipfs.github.io/js-ipfs-unixfs/modules/ipfs_unixfs_importer.html>
14389

144-
## License
90+
# License
14591

14692
Licensed under either of
14793

14894
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
14995
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
15096

151-
## Contribute
97+
# Contribute
15298

15399
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs-unixfs/issues).
154100

‎packages/ipfs-unixfs-importer/package.json

+6-93
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"bugs": {
1212
"url": "https://github.com/ipfs/js-ipfs-unixfs/issues"
1313
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
1418
"keywords": [
1519
"IPFS"
1620
],
17-
"engines": {
18-
"node": ">=16.0.0",
19-
"npm": ">=7.0.0"
20-
},
2121
"type": "module",
2222
"types": "./dist/src/index.d.ts",
2323
"typesVersions": {
@@ -59,94 +59,10 @@
5959
"eslintConfig": {
6060
"extends": "ipfs",
6161
"parserOptions": {
62+
"project": true,
6263
"sourceType": "module"
6364
}
6465
},
65-
"release": {
66-
"branches": [
67-
"master"
68-
],
69-
"plugins": [
70-
[
71-
"@semantic-release/commit-analyzer",
72-
{
73-
"preset": "conventionalcommits",
74-
"releaseRules": [
75-
{
76-
"breaking": true,
77-
"release": "major"
78-
},
79-
{
80-
"revert": true,
81-
"release": "patch"
82-
},
83-
{
84-
"type": "feat",
85-
"release": "minor"
86-
},
87-
{
88-
"type": "fix",
89-
"release": "patch"
90-
},
91-
{
92-
"type": "docs",
93-
"release": "patch"
94-
},
95-
{
96-
"type": "test",
97-
"release": "patch"
98-
},
99-
{
100-
"type": "deps",
101-
"release": "patch"
102-
},
103-
{
104-
"scope": "no-release",
105-
"release": false
106-
}
107-
]
108-
}
109-
],
110-
[
111-
"@semantic-release/release-notes-generator",
112-
{
113-
"preset": "conventionalcommits",
114-
"presetConfig": {
115-
"types": [
116-
{
117-
"type": "feat",
118-
"section": "Features"
119-
},
120-
{
121-
"type": "fix",
122-
"section": "Bug Fixes"
123-
},
124-
{
125-
"type": "chore",
126-
"section": "Trivial Changes"
127-
},
128-
{
129-
"type": "docs",
130-
"section": "Documentation"
131-
},
132-
{
133-
"type": "deps",
134-
"section": "Dependencies"
135-
},
136-
{
137-
"type": "test",
138-
"section": "Tests"
139-
}
140-
]
141-
}
142-
}
143-
],
144-
"@semantic-release/changelog",
145-
"@semantic-release/npm",
146-
"@semantic-release/github",
147-
"@semantic-release/git"
148-
]
149-
},
15066
"scripts": {
15167
"test": "aegir test",
15268
"test:node": "aegir test -t node --cov",
@@ -177,15 +93,12 @@
17793
"uint8arrays": "^5.0.0"
17894
},
17995
"devDependencies": {
180-
"aegir": "^41.3.2",
96+
"aegir": "^42.2.2",
18197
"blockstore-core": "^4.0.1",
18298
"it-last": "^3.0.2",
18399
"wherearewe": "^2.0.1"
184100
},
185101
"browser": {
186102
"fs": false
187-
},
188-
"typedoc": {
189-
"entryPoint": "./src/index.ts"
190103
}
191104
}

‎packages/ipfs-unixfs-importer/src/chunker/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* @packageDocumentation
3+
*
4+
* Chunker functions split an incoming stream of bytes into chunks.
5+
*
6+
* The default is a fixed-size chunker which splits them into equally sized
7+
* chunks though other strategies are available such as Rabin chunking.
8+
*/
9+
110
export interface Chunker { (source: AsyncIterable<Uint8Array>): AsyncIterable<Uint8Array> }
211

312
export { rabin } from './rabin.js'

‎packages/ipfs-unixfs-importer/src/index.ts

+64
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
1+
/**
2+
* @packageDocumentation
3+
*
4+
* @example
5+
*
6+
* Let's create a little directory to import:
7+
*
8+
* ```console
9+
* > cd /tmp
10+
* > mkdir foo
11+
* > echo 'hello' > foo/bar
12+
* > echo 'world' > foo/quux
13+
* ```
14+
*
15+
* And write the importing logic:
16+
*
17+
* ```js
18+
* import { importer } from 'ipfs-unixfs-importer'
19+
* import { MemoryBlockstore } from 'blockstore-core/memory'
20+
* import * as fs from 'node:fs'
21+
*
22+
* // Where the blocks will be stored
23+
* const blockstore = new MemoryBlockstore()
24+
*
25+
* // Import path /tmp/foo/
26+
* const source = [{
27+
* path: '/tmp/foo/bar',
28+
* content: fs.createReadStream('/tmp/foo/bar')
29+
* }, {
30+
* path: '/tmp/foo/quxx',
31+
* content: fs.createReadStream('/tmp/foo/quux')
32+
* }]
33+
*
34+
* for await (const entry of importer(source, blockstore)) {
35+
* console.info(entry)
36+
* }
37+
* ```
38+
*
39+
* When run, metadata about DAGNodes in the created tree is printed until the root:
40+
*
41+
* ```js
42+
* {
43+
* cid: CID, // see https://github.com/multiformats/js-cid
44+
* path: 'tmp/foo/bar',
45+
* unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
46+
* }
47+
* {
48+
* cid: CID, // see https://github.com/multiformats/js-cid
49+
* path: 'tmp/foo/quxx',
50+
* unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
51+
* }
52+
* {
53+
* cid: CID, // see https://github.com/multiformats/js-cid
54+
* path: 'tmp/foo',
55+
* unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
56+
* }
57+
* {
58+
* cid: CID, // see https://github.com/multiformats/js-cid
59+
* path: 'tmp',
60+
* unixfs: UnixFS // see https://github.com/ipfs/js-ipfs-unixfs
61+
* }
62+
* ```
63+
*/
64+
165
import errcode from 'err-code'
266
import first from 'it-first'
367
import parallelBatch from 'it-parallel-batch'

‎packages/ipfs-unixfs-importer/src/layout/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* @packageDocumentation
3+
*
4+
* Layout functions allow customising the shape of final DAGs
5+
*
6+
* {@link https://dag.ipfs.tech} can be used to explore different conigurations.
7+
*/
8+
19
import type { InProgressImportResult } from '../index.js'
210

311
export interface Reducer { (leaves: InProgressImportResult[]): Promise<InProgressImportResult> }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"entryPoints": [
3+
"./src/index.ts",
4+
"./src/chunker/index.ts",
5+
"./src/layout/index.ts"
6+
]
7+
}

‎packages/ipfs-unixfs/README.md

+28-98
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,13 @@
77

88
> JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
99
10-
## Table of contents <!-- omit in toc -->
11-
12-
- [Install](#install)
13-
- [Browser `<script>` tag](#browser-script-tag)
14-
- [Spec](#spec)
15-
- [Use in Node.js](#use-in-nodejs)
16-
- [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
17-
- [Examples](#examples)
18-
- [Create a file composed by several blocks](#create-a-file-composed-by-several-blocks)
19-
- [Create a directory that contains several files](#create-a-directory-that-contains-several-files)
20-
- [UnixFS Data Structure](#unixfs-data-structure)
21-
- [create an unixfs Data element](#create-an-unixfs-data-element)
22-
- [add and remove a block size to the block size list](#add-and-remove-a-block-size-to-the-block-size-list)
23-
- [get total fileSize](#get-total-filesize)
24-
- [marshal and unmarshal](#marshal-and-unmarshal)
25-
- [is this UnixFS entry a directory?](#is-this-unixfs-entry-a-directory)
26-
- [has an mtime been set?](#has-an-mtime-been-set)
27-
- [API Docs](#api-docs)
28-
- [License](#license)
29-
- [Contribute](#contribute)
30-
31-
## Install
10+
# About
3211

33-
```console
34-
$ npm i ipfs-unixfs
35-
```
36-
37-
### Browser `<script>` tag
38-
39-
Loading this module through a script tag will make it's exports available as `IpfsUnixfs` in the global namespace.
40-
41-
```html
42-
<script src="https://unpkg.com/ipfs-unixfs/dist/index.min.js"></script>
43-
```
44-
45-
## Spec
12+
This module contains the protobuf definition of the UnixFS data structure found at the root of all UnixFS DAGs.
4613

47-
The UnixFS spec can be found inside the [ipfs/specs repository](http://github.com/ipfs/specs)
14+
The UnixFS spec can be found in the [ipfs/specs repository](http://github.com/ipfs/specs)
4815

49-
### Use in Node.js
50-
51-
```JavaScript
52-
import { UnixFS } from 'ipfs-unixfs'
53-
```
54-
55-
### Use in a browser with browserify, webpack or any other bundler
56-
57-
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
58-
59-
```JavaScript
60-
import { UnixFS } from 'ipfs-unixfs'
61-
```
62-
63-
## Examples
64-
65-
### Create a file composed by several blocks
16+
## Example - Create a file composed of several blocks
6617

6718
```JavaScript
6819
const data = new UnixFS({ type: 'file' })
@@ -71,50 +22,15 @@ data.addBlockSize(256)
7122
// ...
7223
```
7324

74-
### Create a directory that contains several files
25+
## Example - Create a directory that contains several files
7526

7627
Creating a directory that contains several files is achieve by creating a unixfs element that identifies a MerkleDAG node as a directory. The links of that MerkleDAG node are the files that are contained in this directory.
7728

7829
```JavaScript
7930
const data = new UnixFS({ type: 'directory' })
8031
```
8132

82-
### UnixFS Data Structure
83-
84-
```protobuf
85-
syntax = "proto2";
86-
87-
message Data {
88-
enum DataType {
89-
Raw = 0;
90-
Directory = 1;
91-
File = 2;
92-
Metadata = 3;
93-
Symlink = 4;
94-
HAMTShard = 5;
95-
}
96-
97-
required DataType Type = 1;
98-
optional bytes Data = 2;
99-
optional uint64 filesize = 3;
100-
repeated uint64 blocksizes = 4;
101-
optional uint64 hashType = 5;
102-
optional uint64 fanout = 6;
103-
optional uint32 mode = 7;
104-
optional UnixTime mtime = 8;
105-
}
106-
107-
message UnixTime {
108-
required int64 Seconds = 1;
109-
optional fixed32 FractionalNanoseconds = 2;
110-
}
111-
112-
message Metadata {
113-
optional string MimeType = 1;
114-
}
115-
```
116-
117-
### create an unixfs Data element
33+
## Example - Create an unixfs Data element
11834

11935
```JavaScript
12036
const data = new UnixFS([options])
@@ -134,7 +50,7 @@ const data = new UnixFS([options])
13450
- mode (Number, default `0644` for files, `0755` for directories/hamt-sharded-directories) file mode
13551
- mtime (`Date`, `{ secs, nsecs }`, `{ Seconds, FractionalNanoseconds }`, `[ secs, nsecs ]`): The modification time of this node
13652

137-
### add and remove a block size to the block size list
53+
## Example - Add and remove a block size to the block size list
13854

13955
```JavaScript
14056
data.addBlockSize(<size in bytes>)
@@ -144,20 +60,20 @@ data.addBlockSize(<size in bytes>)
14460
data.removeBlockSize(<index>)
14561
```
14662

147-
### get total fileSize
63+
## Example - Get total fileSize
14864

14965
```JavaScript
15066
data.fileSize() // => size in bytes
15167
```
15268

153-
### marshal and unmarshal
69+
## Example - Marshal and unmarshal
15470

15571
```javascript
15672
const marshaled = data.marshal()
15773
const unmarshaled = Unixfs.unmarshal(marshaled)
15874
```
15975

160-
### is this UnixFS entry a directory?
76+
## Example - Is this UnixFS entry a directory?
16177

16278
```JavaScript
16379
const dir = new Data({ type: 'directory' })
@@ -167,7 +83,7 @@ const file = new Data({ type: 'file' })
16783
file.isDirectory() // false
16884
```
16985

170-
### has an mtime been set?
86+
## Example - Has an mtime been set?
17187

17288
If no modification time has been set, no `mtime` property will be present on the `Data` instance:
17389

@@ -181,18 +97,32 @@ const dir = new Data({ type: 'dir', mtime: new Date() })
18197
dir.mtime // { secs: Number, nsecs: Number }
18298
```
18399

184-
## API Docs
100+
# Install
101+
102+
```console
103+
$ npm i ipfs-unixfs
104+
```
105+
106+
## Browser `<script>` tag
107+
108+
Loading this module through a script tag will make it's exports available as `IpfsUnixfs` in the global namespace.
109+
110+
```html
111+
<script src="https://unpkg.com/ipfs-unixfs/dist/index.min.js"></script>
112+
```
113+
114+
# API Docs
185115

186116
- <https://ipfs.github.io/js-ipfs-unixfs/modules/ipfs_unixfs.html>
187117

188-
## License
118+
# License
189119

190120
Licensed under either of
191121

192122
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
193123
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
194124

195-
## Contribute
125+
# Contribute
196126

197127
Contributions welcome! Please check out [the issues](https://github.com/ipfs/js-ipfs-unixfs/issues).
198128

‎packages/ipfs-unixfs/package.json

+6-93
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"bugs": {
1212
"url": "https://github.com/ipfs/js-ipfs-unixfs/issues"
1313
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
1418
"keywords": [
1519
"IPFS"
1620
],
17-
"engines": {
18-
"node": ">=16.0.0",
19-
"npm": ">=7.0.0"
20-
},
2121
"type": "module",
2222
"types": "./dist/src/index.d.ts",
2323
"files": [
@@ -35,97 +35,13 @@
3535
"eslintConfig": {
3636
"extends": "ipfs",
3737
"parserOptions": {
38+
"project": true,
3839
"sourceType": "module"
3940
},
4041
"ignorePatterns": [
4142
"src/unixfs.d.ts"
4243
]
4344
},
44-
"release": {
45-
"branches": [
46-
"master"
47-
],
48-
"plugins": [
49-
[
50-
"@semantic-release/commit-analyzer",
51-
{
52-
"preset": "conventionalcommits",
53-
"releaseRules": [
54-
{
55-
"breaking": true,
56-
"release": "major"
57-
},
58-
{
59-
"revert": true,
60-
"release": "patch"
61-
},
62-
{
63-
"type": "feat",
64-
"release": "minor"
65-
},
66-
{
67-
"type": "fix",
68-
"release": "patch"
69-
},
70-
{
71-
"type": "docs",
72-
"release": "patch"
73-
},
74-
{
75-
"type": "test",
76-
"release": "patch"
77-
},
78-
{
79-
"type": "deps",
80-
"release": "patch"
81-
},
82-
{
83-
"scope": "no-release",
84-
"release": false
85-
}
86-
]
87-
}
88-
],
89-
[
90-
"@semantic-release/release-notes-generator",
91-
{
92-
"preset": "conventionalcommits",
93-
"presetConfig": {
94-
"types": [
95-
{
96-
"type": "feat",
97-
"section": "Features"
98-
},
99-
{
100-
"type": "fix",
101-
"section": "Bug Fixes"
102-
},
103-
{
104-
"type": "chore",
105-
"section": "Trivial Changes"
106-
},
107-
{
108-
"type": "docs",
109-
"section": "Documentation"
110-
},
111-
{
112-
"type": "deps",
113-
"section": "Dependencies"
114-
},
115-
{
116-
"type": "test",
117-
"section": "Tests"
118-
}
119-
]
120-
}
121-
}
122-
],
123-
"@semantic-release/changelog",
124-
"@semantic-release/npm",
125-
"@semantic-release/github",
126-
"@semantic-release/git"
127-
]
128-
},
12945
"scripts": {
13046
"generate": "protons src/unixfs.proto",
13147
"test": "aegir test",
@@ -144,14 +60,11 @@
14460
"uint8arraylist": "^2.4.3"
14561
},
14662
"devDependencies": {
147-
"aegir": "^41.3.2",
63+
"aegir": "^42.2.2",
14864
"protons": "^7.0.2",
14965
"uint8arrays": "^5.0.0"
15066
},
15167
"browser": {
15268
"fs": false
153-
},
154-
"typedoc": {
155-
"entryPoint": "./src/index.ts"
15669
}
15770
}

‎packages/ipfs-unixfs/src/index.ts

+92
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,95 @@
1+
/**
2+
* @packageDocumentation
3+
*
4+
* This module contains the protobuf definition of the UnixFS data structure found at the root of all UnixFS DAGs.
5+
*
6+
* The UnixFS spec can be found in the [ipfs/specs repository](http://github.com/ipfs/specs)
7+
*
8+
* @example Create a file composed of several blocks
9+
*
10+
* ```JavaScript
11+
* const data = new UnixFS({ type: 'file' })
12+
* data.addBlockSize(256) // add the size of each block
13+
* data.addBlockSize(256)
14+
* // ...
15+
* ```
16+
*
17+
* @example Create a directory that contains several files
18+
*
19+
* Creating a directory that contains several files is achieve by creating a unixfs element that identifies a MerkleDAG node as a directory. The links of that MerkleDAG node are the files that are contained in this directory.
20+
*
21+
* ```JavaScript
22+
* const data = new UnixFS({ type: 'directory' })
23+
* ```
24+
*
25+
* @example Create an unixfs Data element
26+
*
27+
* ```JavaScript
28+
* const data = new UnixFS([options])
29+
* ```
30+
*
31+
* `options` is an optional object argument that might include the following keys:
32+
*
33+
* - type (string, default `file`): The type of UnixFS entry. Can be:
34+
* - `raw`
35+
* - `directory`
36+
* - `file`
37+
* - `metadata`
38+
* - `symlink`
39+
* - `hamt-sharded-directory`
40+
* - data (Uint8Array): The optional data field for this node
41+
* - blockSizes (Array, default: `[]`): If this is a `file` node that is made up of multiple blocks, `blockSizes` is a list numbers that represent the size of the file chunks stored in each child node. It is used to calculate the total file size.
42+
* - mode (Number, default `0644` for files, `0755` for directories/hamt-sharded-directories) file mode
43+
* - mtime (`Date`, `{ secs, nsecs }`, `{ Seconds, FractionalNanoseconds }`, `[ secs, nsecs ]`): The modification time of this node
44+
*
45+
* @example Add and remove a block size to the block size list
46+
*
47+
* ```JavaScript
48+
* data.addBlockSize(<size in bytes>)
49+
* ```
50+
*
51+
* ```JavaScript
52+
* data.removeBlockSize(<index>)
53+
* ```
54+
*
55+
* @example Get total fileSize
56+
*
57+
* ```JavaScript
58+
* data.fileSize() // => size in bytes
59+
* ```
60+
*
61+
* @example Marshal and unmarshal
62+
*
63+
* ```javascript
64+
* const marshaled = data.marshal()
65+
* const unmarshaled = Unixfs.unmarshal(marshaled)
66+
* ```
67+
*
68+
* @example Is this UnixFS entry a directory?
69+
*
70+
* ```JavaScript
71+
* const dir = new Data({ type: 'directory' })
72+
* dir.isDirectory() // true
73+
*
74+
* const file = new Data({ type: 'file' })
75+
* file.isDirectory() // false
76+
* ```
77+
*
78+
* @example Has an mtime been set?
79+
*
80+
* If no modification time has been set, no `mtime` property will be present on the `Data` instance:
81+
*
82+
* ```JavaScript
83+
* const file = new Data({ type: 'file' })
84+
* file.mtime // undefined
85+
*
86+
* Object.prototype.hasOwnProperty.call(file, 'mtime') // false
87+
*
88+
* const dir = new Data({ type: 'dir', mtime: new Date() })
89+
* dir.mtime // { secs: Number, nsecs: Number }
90+
* ```
91+
*/
92+
193
import errcode from 'err-code'
294
import { Data as PBData } from './unixfs.js'
395

‎packages/ipfs-unixfs/typedoc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"entryPoints": [
3+
"./src/index.ts"
4+
],
5+
"readme": "none"
6+
}

‎typedoc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://typedoc.org/schema.json",
3+
"name": "UnixFS",
4+
"exclude": [
5+
"packages/interop"
6+
]
7+
}

0 commit comments

Comments
 (0)
Please sign in to comment.