Skip to content

Commit a23125f

Browse files
committed
fix: fix all mentions of .string()
1 parent 1296956 commit a23125f

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/tutorials/0004-mutable-file-system/02.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ When working with your IPFS node, you'll often want to check the status of a fil
1515

1616
For example, to check the status of a directory called `stuff` located within our root directory ( `/` ), we could call the method like so:
1717

18-
````javascript
18+
```javascript
1919
await ipfs.files.stat('/stuff')
2020
```
2121

src/tutorials/0004-mutable-file-system/10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ipfs.files.read(path, [options])
1313

1414
The `path` provided is the path of the file to read, and it must point to a file rather than a directory.
1515

16-
The `files.read` method returns an Async Iterable that iterates over the file's chunks of data, i.e. Buffers. In our case, we ultimately need to convert Buffers into strings using the method `toString()`. However, the chunks of data within a single file need to be reassembled (concatenated) before the conversion. The [`it-to-buffer`](https://www.npmjs.com/package/it-to-buffer) package can iterate over all of the chunks and put them back together for us. (We've made this package available to you in our challenges as `toBuffer`.)
16+
The `files.read` method returns an Async Iterable that iterates over the file's chunks of data, i.e. Buffers. In our case, we ultimately need to convert Buffers into strings using the method `new TextDecoder().encode(buffer)`. However, the chunks of data within a single file need to be reassembled (concatenated) before the conversion. The [`it-to-buffer`](https://www.npmjs.com/package/it-to-buffer) package can iterate over all of the chunks and put them back together for us. (We've made this package available to you in our challenges as `toBuffer`.)
1717

1818
```js
1919
// the toBuffer variable is globally available (just like ipfs)

src/tutorials/0005-regular-files-api/04-challenge.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Using the `cat` function, retrieve the file's contents and return them as a stri
88

99
**Hints:**
1010

11-
- The `CID` we provide is a string, so it needs to be placed inside quotes. Also, don't forget to convert the buffered contents of the text file to a string using `.toString()` before returning your result.
12-
- You need to concatenate all the chunks of data because the `ipfs.cat` method returns an `Async Iterable`. You can use the package `it-to-buffer` to achieve this.
11+
- The `CID` we provide is a string, so it needs to be placed inside quotes. Also, don't forget to convert the buffered contents of the text file to a string using `new TextDecoder().decode()` before returning your result.
12+
- You need to concatenate all the chunks of data because the `ipfs.cat` method returns an `Async Iterable`. You can use the package `it-to-buffer` to achieve this.

src/tutorials/0005-regular-files-api/04.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `cat` method first searches your own node for the file requested, and if it
1515

1616
The `cat` method returns an Async Iterable that iterates over the file's chunks of data, i.e. Buffers.
1717

18-
A `Buffer` is just a raw collection of bytes and as such doesn't make any assumptions about encodings or the type of data it contains. However, if we know the file being retrieved is a plain text file such as a `.txt`, we can convert its buffered contents to a UTF-8 string (an interpretation of those raw bytes) by calling the JavaScript method `.toString()`.
18+
A `Buffer` is just a raw collection of bytes and as such doesn't make any assumptions about encodings or the type of data it contains. However, if we know the file being retrieved is a plain text file such as a `.txt`, we can convert its buffered contents to a UTF-8 string (an interpretation of those raw bytes) by calling the JavaScript method `new TextDecoder().decode()`.
1919

2020
But since we have multiple buffers of the same file, we need to reassemble them (concatenate) into a single buffer before converting it into a string. The [`it-to-buffer`](https://www.npmjs.com/package/it-to-buffer) package can do just that: iterate over all of the chunks of the file and put them back together for us.
2121

@@ -25,7 +25,7 @@ So if you had the CID for a text file in an IPFS node, you could retrieve the fi
2525
// the toBuffer variable is globally available (just like ipfs)
2626

2727
const bufferedContents = await toBuffer(ipfs.cat('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ')) // returns a Buffer
28-
const stringContents = bufferedContents.toString() // returns a string
28+
const stringContents = new TextEncoder().decode(bufferedContents) // returns a string
2929
```
3030

3131
When you're ready to try this in the real world, you should note that the above example can result in heavy memory usage, depending on the contents of the file being read. If you're working with large files and find this to be the case, you might want to skip using the `it-to-buffer` package and instead process each chunk of data iteratively. The main reason IPFS now returns `Async Iterables` is to provide a built-in option for dealing with potential performance issues.

src/tutorials/0005-regular-files-api/07-challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Based on our file structure, the path could be expressed as:
1515
There are two valid ways to solve this challenge. Take your pick!
1616

1717
**Hints:**
18-
- In the code below we've already taken care of converting the `bufferedContents` to a string before returning the result, as you did yourself previously using `.toString()`.
18+
- In the code below we've already taken care of converting the `bufferedContents` to a string before returning the result, as you did yourself previously using `new TextDecoder().decode()`.
1919
- Don't forget to prepend `/ipfs/` to the IPFS Path string
2020
- You need to concatenate all the data into a single buffer because the `ipfs.cat` method returns an `Async Iterable`. You can use the package `it-to-buffer`.

0 commit comments

Comments
 (0)