Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit bb05266

Browse files
author
Alan Shaw
committed
docs: add globSource and urlSource utility examples
1 parent ad0e273 commit bb05266

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

SPEC/FILES.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,58 @@ Prints out objects like:
156156

157157
Now [ipfs.io/ipfs/Qm...WW](https://ipfs.io/ipfs/QmNz1UBzpdd4HfZ3qir3aPiRdX5a93XwTuDNyXRc6PKhWW) returns the "ABC" string.
158158

159+
**Importing files from the file system:**
160+
161+
Both js-ipfs and js-ipfs-http-client export a utility to make importing files from the file system easier (Note: it not available in the browser).
162+
163+
```js
164+
const IPFS = require('ipfs')
165+
const { globSource } = IPFS
166+
167+
const ipfs = await IPFS.create()
168+
169+
for await (const file of ipfs.add(globSource('./docs', { recursive: true }))) {
170+
console.log(file)
171+
}
172+
173+
/*
174+
{
175+
path: 'docs/assets/anchor.js',
176+
cid: CID('QmVHxRocoWgUChLEvfEyDuuD6qJ4PhdDL2dTLcpUy3dSC2'),
177+
size: 15347
178+
}
179+
{
180+
path: 'docs/assets/bass-addons.css',
181+
hash: CID('QmPiLWKd6yseMWDTgHegb8T7wVS7zWGYgyvfj7dGNt2viQ'),
182+
size: 232
183+
}
184+
...
185+
*/
186+
```
187+
188+
**Importing a file from a URL:**
189+
190+
Both js-ipfs and js-ipfs-http-client export a utility to make importing a file from a URL easier.
191+
192+
```js
193+
const IPFS = require('ipfs')
194+
const { globSource } = IPFS
195+
196+
const ipfs = await IPFS.create()
197+
198+
for await (const file of ipfs.add(urlSource('https://ipfs.io/images/ipfs-logo.svg'))) {
199+
console.log(file)
200+
}
201+
202+
/*
203+
{
204+
path: 'ipfs-logo.svg',
205+
cid: CID('QmTqZhR6f7jzdhLgPArDPnsbZpvvgxzCZycXK7ywkLxSyU'),
206+
size: 3243
207+
}
208+
*/
209+
```
210+
159211
A great source of [examples][] can be found in the tests for this API.
160212

161213
#### `cat`

0 commit comments

Comments
 (0)