Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 34ec036

Browse files
author
Alan Shaw
authored
fix: examples after files API refactor (#1740)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 7dd5005 commit 34ec036

File tree

11 files changed

+26
-26
lines changed

11 files changed

+26
-26
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Using duplex streams to add files to IPFS in the browser
22

3-
If you have a number of files that you'd like to add to IPFS and end up with a hash representing the directory containing your files, you can invoke [`ipfs.files.add`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add) with an array of objects.
3+
If you have a number of files that you'd like to add to IPFS and end up with a hash representing the directory containing your files, you can invoke [`ipfs.add`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add) with an array of objects.
44

5-
But what if you don't know how many there will be in advance? You can add multiple files to a directory in IPFS over time by using [`ipfs.files.addReadableStream`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addreadablestream).
5+
But what if you don't know how many there will be in advance? You can add multiple files to a directory in IPFS over time by using [`ipfs.addReadableStream`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addreadablestream).
66

77
See `index.js` for a working example and open `index.html` in your browser to see it run.

examples/browser-add-readable-stream/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const createFiles = (directory) => {
5353

5454
const streamFiles = (directory, files, cb) => {
5555
// Create a stream to write files to
56-
const stream = ipfs.files.addReadableStream()
56+
const stream = ipfs.addReadableStream()
5757
stream.on('data', function (data) {
5858
log(`Added ${data.path} hash: ${data.hash}`)
5959

examples/browser-browserify/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ node.once('ready', () => console.log('IPFS node is ready'))
99
function store () {
1010
const toStore = document.getElementById('source').value
1111

12-
node.files.add(Buffer.from(toStore), (err, res) => {
12+
node.add(Buffer.from(toStore), (err, res) => {
1313
if (err || !res) {
1414
return console.error('ipfs add error', err, res)
1515
}
@@ -25,7 +25,7 @@ function store () {
2525

2626
function display (hash) {
2727
// buffer: true results in the returned result being a buffer rather than a stream
28-
node.files.cat(hash, (err, data) => {
28+
node.cat(hash, (err, data) => {
2929
if (err) { return console.error('ipfs cat error', err) }
3030

3131
document.getElementById('hash').innerText = hash

examples/browser-readablestream/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ipfs.on('ready', () => {
4545
}
4646

4747
// This stream will contain the requested bytes
48-
stream = ipfs.files.catReadableStream(hashInput.value.trim(), {
48+
stream = ipfs.catReadableStream(hashInput.value.trim(), {
4949
offset: start,
5050
length: end && end - start
5151
})

examples/browser-readablestream/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const dragDrop = (ipfs) => {
3838

3939
const reader = new window.FileReader()
4040
reader.onload = (event) => {
41-
ipfs.files.add({
41+
ipfs.add({
4242
path: file.name,
4343
content: ipfs.types.Buffer.from(event.target.result)
4444
}, {

examples/browser-script-tag/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
document.getElementById("status").innerHTML= 'Node status: ' + (node.isOnline() ? 'online' : 'offline')
1313

14-
// You can write more code here to use it. Use methods like
15-
// node.files.add, node.files.get. See the API docs here:
14+
// You can write more code here to use it. Use methods like
15+
// node.add, node.get. See the API docs here:
1616
// https://github.com/ipfs/interface-ipfs-core
1717
})
1818
</script>
@@ -28,7 +28,7 @@ <h2>Some suggestions</h2>
2828
<p>Try adding a new file:</p>
2929

3030
<code style="display:block; white-space:pre-wrap; background-color:#d7d6d6">
31-
node.files.add(new node.types.Buffer('Hello world!'), (err, filesAdded) => {
31+
node.add(new node.types.Buffer('Hello world!'), (err, filesAdded) => {
3232
if (err) {
3333
return console.error('Error - ipfs add', err, res)
3434
}
@@ -40,7 +40,7 @@ <h2>Some suggestions</h2>
4040
<p>You can cat that same file. If you used the exact same string as above ('Hello world!') you should have an hash like this: 'QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY'</p>
4141

4242
<code style="display:block; white-space:pre-wrap; background-color:#d7d6d6">
43-
node.files.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
43+
node.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
4444
if (err) {
4545
return console.error('Error - ipfs files cat', err, res)
4646
}

examples/browser-webpack/src/components/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ class App extends React.Component {
4545
})
4646
})
4747

48-
node.files.add([Buffer.from(stringToUse)], (err, filesAdded) => {
48+
node.add([Buffer.from(stringToUse)], (err, filesAdded) => {
4949
if (err) { throw err }
5050

5151
const hash = filesAdded[0].hash
5252
self.setState({ added_file_hash: hash })
5353

54-
node.files.cat(hash, (err, data) => {
54+
node.cat(hash, (err, data) => {
5555
if (err) { throw err }
5656
self.setState({ added_file_contents: data.toString() })
5757
})

examples/custom-ipfs-repo/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ node.on('ready', () => {
7575
})
7676
// Once we have the version, let's add a file to IPFS
7777
.then(() => {
78-
return node.files.add({
78+
return node.add({
7979
path: 'test-data.txt',
8080
content: Buffer.from('We are using a customized repo!')
8181
})
8282
})
8383
// Log out the added files metadata and cat the file from IPFS
8484
.then((filesAdded) => {
8585
console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash)
86-
return node.files.cat(filesAdded[0].hash)
86+
return node.cat(filesAdded[0].hash)
8787
})
8888
// Print out the files contents to console
8989
.then((data) => {

examples/exchange-files-in-browser/public/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function getFile () {
161161

162162
FILES.push(hash)
163163

164-
node.files.get(hash)
164+
node.get(hash)
165165
.then((files) => {
166166
files.forEach((file) => {
167167
if (file.content) {
@@ -206,7 +206,7 @@ function onDrop (event) {
206206
.then((buffer) => {
207207
fileSize = file.size
208208

209-
node.files.add({
209+
node.add({
210210
path: file.name,
211211
content: Buffer.from(buffer)
212212
}, { wrap: true, progress: updateProgress }, (err, filesAdded) => {

examples/ipfs-101/1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ node.on('ready', async () => {
99

1010
console.log('Version:', version.version)
1111

12-
const filesAdded = await node.files.add({
12+
const filesAdded = await node.add({
1313
path: 'hello.txt',
1414
content: Buffer.from('Hello World 101')
1515
})
1616

1717
console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)
1818

19-
const fileBuffer = await node.files.cat(filesAdded[0].hash)
19+
const fileBuffer = await node.cat(filesAdded[0].hash)
2020

2121
console.log('Added file contents:', fileBuffer.toString())
2222
})

examples/ipfs-101/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Running the code above gets you:
3838
Version: 0.31.2
3939
```
4040

41-
Now let's make it more interesting and add a file to IPFS using `node.files.add`. A file consists of a path and content.
41+
Now let's make it more interesting and add a file to IPFS using `node.add`. A file consists of a path and content.
4242

4343
You can learn about the IPFS File API at [interface-ipfs-core](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md).
4444

@@ -47,12 +47,12 @@ node.on('ready', async () => {
4747
const version = await node.version()
4848

4949
console.log('Version:', version.version)
50-
51-
const filesAdded = await node.files.add({
50+
51+
const filesAdded = await node.add({
5252
path: 'hello.txt',
5353
content: Buffer.from('Hello World 101')
5454
})
55-
55+
5656
console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)
5757
})
5858
```
@@ -76,14 +76,14 @@ node.on('ready', async () => {
7676

7777
console.log('Version:', version.version)
7878

79-
const filesAdded = await node.files.add({
79+
const filesAdded = await node.add({
8080
path: 'hello.txt',
8181
content: Buffer.from('Hello World 101')
8282
})
83-
83+
8484
console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)
8585

86-
const fileBuffer = await node.files.cat(filesAdded[0].hash)
86+
const fileBuffer = await node.cat(filesAdded[0].hash)
8787

8888
console.log('Added file contents:', fileBuffer.toString())
8989
})

0 commit comments

Comments
 (0)