Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/FS/copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Copies a file or directory from one location to another.
```js
puter.fs.copy(source, destination)
puter.fs.copy(source, destination, options)
puter.fs.copy(options)
```

## Parameters
Expand All @@ -27,6 +28,8 @@ The path to the destination directory. If destination is a directory then the fi

The options for the `copy` operation. The following options are supported:

- `source` (String) - Path to the file or directory to copy. Required when passing options as the only argument.
- `destination` (String) - Path to the destination. Required when passing options as the only argument.
- `overwrite` (Boolean) - Whether to overwrite the destination file or directory if it already exists. Defaults to `false`.
- `dedupeName` (Boolean) - Whether to deduplicate the file or directory name if it already exists. Defaults to `false`.
- `newName` (String) - The new name to use for the copied file or directory. Defaults to `undefined`.
Expand Down
12 changes: 7 additions & 5 deletions src/FS/delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ Deletes a file or directory.
## Syntax

```js
puter.fs.delete(path)
puter.fs.delete(path, options)
puter.fs.delete(paths)
puter.fs.delete(paths, options)
puter.fs.delete(options)
```

## Parameters

#### `path` (String) (required)
#### `paths` (String | String[]) (required)

Path of the file or directory to delete.
If `path` is not absolute, it will be resolved relative to the app's root directory.
A single path or array of paths of the file(s) or directory(ies) to delete.
If a path is not absolute, it will be resolved relative to the app's root directory.

#### `options` (Object) (optional)

The options for the `delete` operation. The following options are supported:

- `paths` (String | String[]) - A single path or array of paths to delete. Required when passing options as the only argument.
- `recursive` (Boolean) - Whether to delete the directory recursively. Defaults to `true`.
- `descendantsOnly` (Boolean) - Whether to delete only the descendants of the directory and not the directory itself. Defaults to `false`.

Expand Down
2 changes: 1 addition & 1 deletion src/FS/getReadURL.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The path to the file to read.

The number of seconds until the URL expires. If not provided, the URL will expire in 24 hours.

## Returns
## Return value

A promise that resolves to a URL string that can be used to read the file.

Expand Down
18 changes: 13 additions & 5 deletions src/FS/mkdir.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ platforms: [websites, apps, nodejs, workers]
Allows you to create a directory.

## Syntax

```js
puter.fs.mkdir(path)
puter.fs.mkdir(path, options)
puter.fs.mkdir(options)
```

## Parameters
#### `path` (string) (required)

#### `path` (String) (required)

The path to the directory to create.
If path is not absolute, it will be resolved relative to the app's root directory.

#### `options` (object)
#### `options` (Object)

The options for the `mkdir` operation. The following options are supported:
- `overwrite` (boolean) - Whether to overwrite the directory if it already exists. Defaults to `false`.
- `dedupeName` (boolean) - Whether to deduplicate the directory name if it already exists. Defaults to `false`.
- `createMissingParents` (boolean) - Whether to create missing parent directories. Defaults to `false`.

- `path` (String) The directory path to be created if not specified via function parameter.
- `overwrite` (Boolean) - Whether to overwrite the directory if it already exists. Defaults to `false`.
- `dedupeName` (Boolean) - Whether to deduplicate the directory name if it already exists. Defaults to `false`.
- `createMissingParents` (Boolean) - Whether to create missing parent directories. Defaults to `false`.

## Return value

Returns a `Promise` that resolves to the [`FSItem`](/Objects/fsitem) object of the created directory.

## Examples
Expand Down
9 changes: 9 additions & 0 deletions src/FS/move.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,31 @@ Moves a file or a directory from one location to another.
```js
puter.fs.move(source, destination)
puter.fs.move(source, destination, options)
puter.fs.move(options)
```

## Parameters

#### `source` (String) (Required)

The path to the file or directory to move.

#### `destination` (String) (Required)

The path to the destination directory. If destination is a directory then the file or directory will be moved into that directory using the same name as the source file or directory. If the destination is a file, we overwrite if overwrite is `true`, otherwise we error.

#### `options` (Object) (Optional)

The options for the `move` operation. The following options are supported:

- `source` (String) - Path to the file or directory to move. Required when passing options as the only argument.
- `destination` (String) - Path to the destination. Required when passing options as the only argument.
- `overwrite` (Boolean) - Whether to overwrite the destination file or directory if it already exists. Defaults to `false`.
- `dedupeName` (Boolean) - Whether to deduplicate the file or directory name if it already exists. Defaults to `false`.
- `createMissingParents` (Boolean) - Whether to create missing parent directories. Defaults to `false`.

## Return value

A `Promise` that will resolve to the [`FSItem`](/Objects/fsitem) object of the moved file or directory. If the source file or directory does not exist, the promise will be rejected with an error.

## Examples
Expand Down
7 changes: 6 additions & 1 deletion src/FS/read.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,32 @@ platforms: [websites, apps, nodejs, workers]
Reads data from a file.

## Syntax

```js
puter.fs.read(path)
puter.fs.read(path, options)
puter.fs.read(options)
```

## Parameters

#### `path` (String) (required)

Path of the file to read.
If `path` is not absolute, it will be resolved relative to the app's root directory.

#### `options` (Object) (optional)

An object with the following properties:

- `path` (String) - Path to the file to read. Required when passing options as the only argument.
- `offset` (Number) (optional)
The offset to start reading from.

- `byte_count` (Number) (required if `offset` is provided)
The number of bytes to read from the offset.

## Return value

A `Promise` that will resolve to a `Blob` object containing the contents of the file.

## Examples
Expand Down
19 changes: 8 additions & 11 deletions src/FS/readdir.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ platforms: [websites, apps, nodejs, workers]
Reads the contents of a directory, returning an array of items (files and directories) within it. This method is useful for listing all items in a specified directory in the Puter cloud storage.

## Syntax

```js
puter.fs.readdir(path)
puter.fs.readdir(path, options)
Expand All @@ -15,24 +16,20 @@ puter.fs.readdir(options)

## Parameters

#### `path` (string)
The path to the directory to read.
If `path` is not absolute, it will be resolved relative to the app's root directory.


#### `options` (object) (optional)
#### `path` (String)

<br>

- `options.path` (string) (optional)
The path to the directory to read.
If `path` is not absolute, it will be resolved relative to the app's root directory.

- `options.uid` (string) (optional)
The UID of the directory to read.
#### `options` (Object) (optional)

An object with the following properties:

- `path` (String) - The path to the directory to read. Required when passing options as the only argument.
- `uid` (String) (optional) - The UID of the directory to read.

## Return value

A `Promise` that resolves to an array of [`FSItem`](/Objects/fsitem/) objects (files and directories) within the specified directory.

## Examples
Expand Down
14 changes: 14 additions & 0 deletions src/FS/rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@ platforms: [websites, apps, nodejs, workers]
Renames a file or directory to a new name. This method allows you to change the name of a file or directory in the Puter cloud storage.

## Syntax

```js
puter.fs.rename(path, newName)
puter.fs.rename(options)
```

## Parameters

#### `path` (string)

The path to the file or directory to rename.
If `path` is not absolute, it will be resolved relative to the app's root directory.

#### `newName` (string)

The new name of the file or directory.

#### `options` (Object)

The options for the `rename` operation. The following options are supported:

- `path` (String) - Path to the file or directory to rename. Required when passing options as the only argument.
- `uid` (String) - The UID of the file or directory to rename. Can be used instead of `path`.
- `newName` (String) - The new name for the file or directory. Required when passing options as the only argument.

## Return value

Returns a promise that resolves to the [`FSItem`](/Objects/fsitem) object of the renamed file or directory.

## Examples
Expand Down
19 changes: 17 additions & 2 deletions src/FS/stat.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,30 @@ This method allows you to get information about a file or directory.
## Syntax

```js
puter.fs.stat(path)
puter.fs.stat(path, options)
puter.fs.stat(options)
```

## Parameters
#### `path` (string) (required)

#### `path` (String) (required)

The path to the file or directory to get information about.
If `path` is not absolute, it will be resolved relative to the app's root directory.

#### `options` (Object) (optional)

An object with the following properties:

- `path` (String) - Path to the file or directory. Required when passing options as the only argument.
- `uid` (String) - The UID of the file or directory. Can be used instead of `path`.
- `returnSubdomains` (Boolean) - Whether to return subdomain information. Defaults to `false`.
- `returnPermissions` (Boolean) - Whether to return permission information. Defaults to `false`.
- `returnVersions` (Boolean) - Whether to return version information. Defaults to `false`.
- `returnSize` (Boolean) - Whether to return size information. Defaults to `false`.

## Return value

A `Promise` that resolves to the [`FSItem`](/Objects/fsitem) object of the specified file or directory.

## Examples
Expand Down
13 changes: 11 additions & 2 deletions src/FS/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ puter.fs.upload(items, dirPath, options)
```

## Parameters
#### `items` (Array) (required)

#### `items` (Object) (required)

The items to upload to the Puter filesystem. `items` can be an `InputFileList`, `FileList`, `Array` of `File` objects, or an `Array` of `Blob` objects.

#### `dirPath` (String) (optional)

The path of the directory to upload the items to. If not set, the items will be uploaded to the app's root directory.

#### `options` (Object) (optional)
A set of key/value pairs that configure the upload process.

A set of key/value pairs that configure the upload process. The following options are supported:

- `overwrite` (Boolean) - Whether to overwrite the destination file if it already exists. Defaults to `false`.
- `dedupeName` (Boolean) - Whether to deduplicate the file name if it already exists. Defaults to `false`.
- `createMissingParents` (Boolean) - Whether to create missing parent directories. Defaults to `false`.

## Return value

Returns a `Promise` that resolves to:

- A single [`FSItem`](/Objects/fsitem/) object if `items` parameter contains one item
- An array of [`FSItem`](/Objects/fsitem/) objects if `items` parameter contains multiple items

Expand Down
17 changes: 14 additions & 3 deletions src/FS/write.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,34 @@ Writes data to a specified file path. This method is useful for creating new fil
puter.fs.write(path)
puter.fs.write(path, data)
puter.fs.write(path, data, options)
puter.fs.write(file)
```

## Parameters
#### `path` (string) (required)

#### `path` (String) (required)

The path to the file to write to.
If path is not absolute, it will be resolved relative to the app's root directory.

#### `data` (string|File|Blob)
#### `data` (String|File|Blob) (required)

The data to write to the file.

#### `options` (object)
#### `options` (Object)

The options for the `write` operation. The following options are supported:

- `overwrite` (boolean) - Whether to overwrite the file if it already exists. Defaults to `true`.
- `dedupeName` (boolean) - Whether to deduplicate the file name if it already exists. Defaults to `false`.
- `createMissingParents` (boolean) - Whether to create missing parent directories. Defaults to `false`.

#### `file` (File)

An alternative to `path` and `data`. A `File` object to write directly, where the file path will be derived from the file's name.

## Return value

Returns a `Promise` that resolves to the [`FSItem`](/Objects/fsitem) object of the written file.

## Examples
Expand Down