diff --git a/examples/browser-add-readable-stream/README.md b/examples/browser-add-readable-stream/README.md index 8e7f60bd9c..3b0cd3e596 100644 --- a/examples/browser-add-readable-stream/README.md +++ b/examples/browser-add-readable-stream/README.md @@ -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. diff --git a/examples/browser-add-readable-stream/index.js b/examples/browser-add-readable-stream/index.js index 7e56c42f65..a989c007dc 100644 --- a/examples/browser-add-readable-stream/index.js +++ b/examples/browser-add-readable-stream/index.js @@ -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}`) diff --git a/examples/browser-browserify/src/index.js b/examples/browser-browserify/src/index.js index 3319115cfe..62e23e5fa8 100644 --- a/examples/browser-browserify/src/index.js +++ b/examples/browser-browserify/src/index.js @@ -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) } @@ -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 diff --git a/examples/browser-readablestream/index.js b/examples/browser-readablestream/index.js index 7a2a969fa1..9b09b1beaf 100644 --- a/examples/browser-readablestream/index.js +++ b/examples/browser-readablestream/index.js @@ -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 }) diff --git a/examples/browser-readablestream/utils.js b/examples/browser-readablestream/utils.js index f0b3e2e580..28180f37e2 100644 --- a/examples/browser-readablestream/utils.js +++ b/examples/browser-readablestream/utils.js @@ -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) }, { diff --git a/examples/browser-script-tag/index.html b/examples/browser-script-tag/index.html index f95a295fd7..521be91c24 100644 --- a/examples/browser-script-tag/index.html +++ b/examples/browser-script-tag/index.html @@ -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 }) @@ -28,7 +28,7 @@
Try adding a new file:
- 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)
}
@@ -40,7 +40,7 @@ Some suggestions
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'
- node.files.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
+ node.cat('QmQzCQn4puG4qu8PVysxZmscmQ5vT1ZXpqo7f58Uh9QfyY', function (err, data) {
if (err) {
return console.error('Error - ipfs files cat', err, res)
}
diff --git a/examples/browser-webpack/src/components/app.js b/examples/browser-webpack/src/components/app.js
index 94a191c8ad..9ae0da0d82 100644
--- a/examples/browser-webpack/src/components/app.js
+++ b/examples/browser-webpack/src/components/app.js
@@ -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() })
})
diff --git a/examples/custom-ipfs-repo/index.js b/examples/custom-ipfs-repo/index.js
index 8122a5433c..ca492fc039 100644
--- a/examples/custom-ipfs-repo/index.js
+++ b/examples/custom-ipfs-repo/index.js
@@ -75,7 +75,7 @@ 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!')
})
@@ -83,7 +83,7 @@ node.on('ready', () => {
// 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) => {
diff --git a/examples/exchange-files-in-browser/public/app.js b/examples/exchange-files-in-browser/public/app.js
index cb38e3546c..31fed7abcf 100644
--- a/examples/exchange-files-in-browser/public/app.js
+++ b/examples/exchange-files-in-browser/public/app.js
@@ -161,7 +161,7 @@ function getFile () {
FILES.push(hash)
- node.files.get(hash)
+ node.get(hash)
.then((files) => {
files.forEach((file) => {
if (file.content) {
@@ -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) => {
diff --git a/examples/ipfs-101/1.js b/examples/ipfs-101/1.js
index 664af3d90c..e0fbbd3cb9 100644
--- a/examples/ipfs-101/1.js
+++ b/examples/ipfs-101/1.js
@@ -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())
})
diff --git a/examples/ipfs-101/README.md b/examples/ipfs-101/README.md
index 98e969f534..1350777e70 100644
--- a/examples/ipfs-101/README.md
+++ b/examples/ipfs-101/README.md
@@ -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).
@@ -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)
})
```
@@ -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())
})