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

Commit

Permalink
fix: examples after files API refactor (#1740)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw authored Nov 30, 2018
1 parent 7dd5005 commit 34ec036
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions examples/browser-add-readable-stream/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Using duplex streams to add files to IPFS in the browser

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.
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.

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).
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).

See `index.js` for a working example and open `index.html` in your browser to see it run.
2 changes: 1 addition & 1 deletion examples/browser-add-readable-stream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const createFiles = (directory) => {

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

Expand Down
4 changes: 2 additions & 2 deletions examples/browser-browserify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ node.once('ready', () => console.log('IPFS node is ready'))
function store () {
const toStore = document.getElementById('source').value

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

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

document.getElementById('hash').innerText = hash
Expand Down
2 changes: 1 addition & 1 deletion examples/browser-readablestream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ipfs.on('ready', () => {
}

// This stream will contain the requested bytes
stream = ipfs.files.catReadableStream(hashInput.value.trim(), {
stream = ipfs.catReadableStream(hashInput.value.trim(), {
offset: start,
length: end && end - start
})
Expand Down
2 changes: 1 addition & 1 deletion examples/browser-readablestream/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const dragDrop = (ipfs) => {

const reader = new window.FileReader()
reader.onload = (event) => {
ipfs.files.add({
ipfs.add({
path: file.name,
content: ipfs.types.Buffer.from(event.target.result)
}, {
Expand Down
8 changes: 4 additions & 4 deletions examples/browser-script-tag/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

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

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

<code style="display:block; white-space:pre-wrap; background-color:#d7d6d6">
node.files.add(new node.types.Buffer('Hello world!'), (err, filesAdded) => {
node.add(new node.types.Buffer('Hello world!'), (err, filesAdded) => {
if (err) {
return console.error('Error - ipfs add', err, res)
}
Expand All @@ -40,7 +40,7 @@ <h2>Some suggestions</h2>
<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>

<code style="display:block; white-space:pre-wrap; background-color:#d7d6d6">
node.files.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
node.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
if (err) {
return console.error('Error - ipfs files cat', err, res)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/browser-webpack/src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class App extends React.Component {
})
})

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

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

node.files.cat(hash, (err, data) => {
node.cat(hash, (err, data) => {
if (err) { throw err }
self.setState({ added_file_contents: data.toString() })
})
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-ipfs-repo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ node.on('ready', () => {
})
// Once we have the version, let's add a file to IPFS
.then(() => {
return node.files.add({
return node.add({
path: 'test-data.txt',
content: Buffer.from('We are using a customized repo!')
})
})
// Log out the added files metadata and cat the file from IPFS
.then((filesAdded) => {
console.log('\nAdded file:', filesAdded[0].path, filesAdded[0].hash)
return node.files.cat(filesAdded[0].hash)
return node.cat(filesAdded[0].hash)
})
// Print out the files contents to console
.then((data) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/exchange-files-in-browser/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function getFile () {

FILES.push(hash)

node.files.get(hash)
node.get(hash)
.then((files) => {
files.forEach((file) => {
if (file.content) {
Expand Down Expand Up @@ -206,7 +206,7 @@ function onDrop (event) {
.then((buffer) => {
fileSize = file.size

node.files.add({
node.add({
path: file.name,
content: Buffer.from(buffer)
}, { wrap: true, progress: updateProgress }, (err, filesAdded) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/ipfs-101/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ node.on('ready', async () => {

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

const filesAdded = await node.files.add({
const filesAdded = await node.add({
path: 'hello.txt',
content: Buffer.from('Hello World 101')
})

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

const fileBuffer = await node.files.cat(filesAdded[0].hash)
const fileBuffer = await node.cat(filesAdded[0].hash)

console.log('Added file contents:', fileBuffer.toString())
})
14 changes: 7 additions & 7 deletions examples/ipfs-101/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Running the code above gets you:
Version: 0.31.2
```

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.
Now let's make it more interesting and add a file to IPFS using `node.add`. A file consists of a path and content.

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

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

console.log('Version:', version.version)
const filesAdded = await node.files.add({

const filesAdded = await node.add({
path: 'hello.txt',
content: Buffer.from('Hello World 101')
})

console.log('Added file:', filesAdded[0].path, filesAdded[0].hash)
})
```
Expand All @@ -76,14 +76,14 @@ node.on('ready', async () => {

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

const filesAdded = await node.files.add({
const filesAdded = await node.add({
path: 'hello.txt',
content: Buffer.from('Hello World 101')
})

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

const fileBuffer = await node.files.cat(filesAdded[0].hash)
const fileBuffer = await node.cat(filesAdded[0].hash)

console.log('Added file contents:', fileBuffer.toString())
})
Expand Down

0 comments on commit 34ec036

Please sign in to comment.