Skip to content

Commit

Permalink
Remove fs.add and fs.cat (#465)
Browse files Browse the repository at this point in the history
* Closes #440

* Update readme
  • Loading branch information
icidasset authored Jan 19, 2023
1 parent 7af4952 commit 57beaf1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

### v0.36.0

#### Breaking changes

Removes the `fs.add` and `fs.cat` functions, use `fs.read` and `fs.write` instead.

#### Additions

- Adds `program.recoverFileSystem({ newUsername, oldUsername, readKey })` shorthand method so apps will no longer have to implement the FS recovery flow manually.
- Adds `program.accountDID(username)` shorthand method to retrieve the root DID of a given account username.


### v0.35.2

Fixes issue with the types of the `path.appData` function. Now has the correct overloads.
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,13 @@ That's it, you have successfully created a Webnative app! 🚀
## Basics

WNFS exposes a familiar POSIX-style interface:
- `add`: add a file
- `cat`: retrieve a file
- `exists`: check if a file or directory exists
- `ls`: list a directory
- `mkdir`: create a directory
- `mv`: move a file or directory
- `read`: alias for `cat`
- `read`: read from a file
- `rm`: remove a file or directory
- `write`: alias for `add`
- `write`: write to a file


## Versioning
Expand Down
16 changes: 3 additions & 13 deletions src/fs/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class FileSystem implements API {
// POSIX INTERFACE (FILES)
// -----------------------

async add(
async write(
path: DistinctivePath,
content: Uint8Array | SoftLink | SoftLink[] | Record<string, SoftLink>,
options: MutationOptions = {}
Expand Down Expand Up @@ -332,7 +332,7 @@ export class FileSystem implements API {
return this
}

async cat(path: FilePath): Promise<Uint8Array> {
async read(path: FilePath): Promise<Uint8Array> {
if (Path.isDirectory(path)) throw new Error("`cat` only accepts file paths")
return this.runOnNode(path, {
public: async (root, relPath) => {
Expand All @@ -346,16 +346,6 @@ export class FileSystem implements API {
})
}

async read(path: FilePath): Promise<Uint8Array | null> {
if (Path.isDirectory(path)) throw new Error("`read` only accepts file paths")
return this.cat(path)
}

async write(path: FilePath, content: Uint8Array, options: MutationOptions = {}): Promise<this> {
if (Path.isDirectory(path)) throw new Error("`write` only accepts file paths")
return this.add(path, content, options)
}


// POSIX INTERFACE (GENERAL)
// -------------------------
Expand Down Expand Up @@ -584,7 +574,7 @@ export class FileSystem implements API {
*/
async acceptShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise<this> {
const share = await this.loadShare({ shareId, sharedBy })
await this.add(
await this.write(
Path.directory(Branch.Private, "Shared with me", sharedBy),
await share.ls([]).then(Object.values).then(links => links.filter(FsTypeChecks.isSoftLink))
)
Expand Down
3 changes: 1 addition & 2 deletions src/fs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ export interface Posix {
mkdir(path: DirectoryPath, options?: MutationOptions): Promise<this>

// Files
add(
write(
path: DistinctivePath,
content: Uint8Array | SoftLink | SoftLink[] | Record<string, SoftLink>,
options?: MutationOptions
): Promise<this>

read(path: FilePath): Promise<Uint8Array | null>
write(path: FilePath, content: Uint8Array, options?: MutationOptions): Promise<this>
}

export interface Sharing {
Expand Down

0 comments on commit 57beaf1

Please sign in to comment.