Skip to content

Commit 88b23b0

Browse files
BjrIntachingbrain
andauthored
docs: update docs to use MFS style API (#4)
The MFS API does not return a CID from every operation so update the docs to reflect that. --------- Co-authored-by: achingbrain <alex@achingbrain.net>
1 parent 351fae7 commit 88b23b0

File tree

1 file changed

+43
-48
lines changed

1 file changed

+43
-48
lines changed

packages/mfs/src/index.ts

+43-48
Original file line numberDiff line numberDiff line change
@@ -88,154 +88,149 @@ export interface RmOptions extends UnixFsRmOptions {
8888
*/
8989
export interface MFS {
9090
/**
91-
* Add a single `Uint8Array` to your Helia node as a file.
91+
* Add a single `Uint8Array` to your MFS as a file.
9292
*
9393
* @example
9494
*
9595
* ```typescript
96-
* const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
97-
*
98-
* console.info(cid)
96+
* await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
9997
* ```
10098
*/
10199
writeBytes: (bytes: Uint8Array, path: string, options?: Partial<WriteOptions>) => Promise<void>
102100

103101
/**
104-
* Add a stream of `Uint8Array` to your Helia node as a file.
102+
* Add a stream of `Uint8Array` to your MFS as a file.
105103
*
106104
* @example
107105
*
108106
* ```typescript
109107
* import fs from 'node:fs'
110108
*
111109
* const stream = fs.createReadStream('./foo.txt')
112-
* const cid = await fs.addByteStream(stream)
113-
*
114-
* console.info(cid)
110+
* await fs.writeByteStream(stream, '/foo.txt')
115111
* ```
116112
*/
117113
writeByteStream: (bytes: ByteStream, path: string, options?: Partial<WriteOptions>) => Promise<void>
118114

119115
/**
120-
* Retrieve the contents of a file from your Helia node.
116+
* Retrieve the contents of a file from your MFS.
121117
*
122118
* @example
123119
*
124120
* ```typescript
125-
* for await (const buf of fs.cat(cid)) {
121+
* for await (const buf of fs.cat('/foo.txt')) {
126122
* console.info(buf)
127123
* }
128124
* ```
129125
*/
130126
cat: (path: string, options?: Partial<CatOptions>) => AsyncIterable<Uint8Array>
131127

132128
/**
133-
* Change the permissions on a file or directory in a DAG
129+
* Change the permissions on a file or directory in your MFS
134130
*
135131
* @example
136132
*
137133
* ```typescript
138-
* const beforeCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
139-
* const beforeStats = await fs.stat(beforeCid)
134+
* await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
135+
* const beforeStats = await fs.stat('/foo.txt')
140136
*
141-
* const afterCid = await fs.chmod(cid, 0x755)
142-
* const afterStats = await fs.stat(afterCid)
137+
* await fs.chmod('/foo.txt', 0x755)
138+
* const afterStats = await fs.stat('/foo.txt')
143139
*
144-
* console.info(beforeCid, beforeStats)
145-
* console.info(afterCid, afterStats)
140+
* console.info(beforeStats)
141+
* console.info(afterStats)
146142
* ```
147143
*/
148144
chmod: (path: string, mode: number, options?: Partial<ChmodOptions>) => Promise<void>
149145

150146
/**
151-
* Add a file or directory to a target directory.
147+
* Add a file or directory to a target directory in your MFS.
152148
*
153149
* @example
154150
*
155151
* ```typescript
156-
* const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
157-
* const directoryCid = await fs.addDirectory()
152+
* await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
153+
* await fs.mkdir('/bar')
154+
*
155+
* await fs.cp('/foo.txt', '/bar')
156+
* ```
157+
*
158+
* Copy a file from one place to another in your MFS.
159+
*
160+
* @example
158161
*
159-
* const updatedCid = await fs.cp(fileCid, directoryCid, 'foo.txt')
162+
* ```typescript
163+
* await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
160164
*
161-
* console.info(updatedCid)
165+
* await fs.cp('/foo.txt', '/bar.txt')
162166
* ```
163167
*/
164168
cp: (source: CID | string, destination: string, options?: Partial<CpOptions>) => Promise<void>
165169

166170
/**
167-
* List directory contents.
171+
* List directory contents from your MFS.
168172
*
169173
* @example
170174
*
171175
* ```typescript
172-
* for await (const entry of fs.ls(directoryCid)) {
173-
* console.info(etnry)
176+
* for await (const entry of fs.ls('/bar')) {
177+
* console.info(entry)
174178
* }
175179
* ```
176180
*/
177181
ls: (path?: string, options?: Partial<LsOptions>) => AsyncIterable<UnixFSEntry>
178182

179183
/**
180-
* Make a new directory under an existing directory.
184+
* Make a new directory in your MFS.
181185
*
182186
* @example
183187
*
184188
* ```typescript
185-
* const directoryCid = await fs.addDirectory()
186-
*
187-
* const updatedCid = await fs.mkdir(directoryCid, 'new-dir')
188-
*
189-
* console.info(updatedCid)
189+
* await fs.mkdir('/new-dir')
190190
* ```
191191
*/
192192
mkdir: (path: string, options?: Partial<MkdirOptions>) => Promise<void>
193193

194194
/**
195-
* Remove a file or directory from an existing directory.
195+
* Remove a file or directory from your MFS.
196196
*
197197
* @example
198198
*
199199
* ```typescript
200-
* const directoryCid = await fs.addDirectory()
201-
* const updatedCid = await fs.mkdir(directoryCid, 'new-dir')
202-
*
203-
* const finalCid = await fs.rm(updatedCid, 'new-dir')
204-
*
205-
* console.info(finalCid)
200+
* await fs.mkdir('/new-dir')
201+
* await fs.rm('/new-dir')
206202
* ```
207203
*/
208204
rm: (path: string, options?: Partial<RmOptions>) => Promise<void>
209205

210206
/**
211-
* Return statistics about a UnixFS DAG.
207+
* Return statistics about a UnixFS DAG in your MFS.
212208
*
213209
* @example
214210
*
215211
* ```typescript
216-
* const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
217-
*
218-
* const stats = await fs.stat(fileCid)
212+
* await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
219213
*
214+
* const stats = await fs.stat('/foo.txt')
220215
* console.info(stats)
221216
* ```
222217
*/
223218
stat: (path: string, options?: Partial<StatOptions>) => Promise<UnixFSStats>
224219

225220
/**
226-
* Update the mtime of a UnixFS DAG
221+
* Update the mtime of a UnixFS DAG in your MFS.
227222
*
228223
* @example
229224
*
230225
* ```typescript
231-
* const beforeCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3]))
232-
* const beforeStats = await fs.stat(beforeCid)
226+
* await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/foo.txt')
227+
* const beforeStats = await fs.stat('/foo.txt')
233228
*
234-
* const afterCid = await fs.touch(beforeCid)
229+
* await fs.touch('/foo.txt')
235230
* const afterStats = await fs.stat(afterCid)
236231
*
237-
* console.info(beforeCid, beforeStats)
238-
* console.info(afterCid, afterStats)
232+
* console.info(beforeStats)
233+
* console.info(afterStats)
239234
* ```
240235
*/
241236
touch: (path: string, options?: Partial<TouchOptions>) => Promise<void>

0 commit comments

Comments
 (0)