Skip to content

Commit

Permalink
Cheerp x webdevice reference (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
AtibQur authored Feb 3, 2025
1 parent eff8d66 commit 6fe7c96
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ CheerpX implements UNIX-style virtual filesystems with multiple mount points, pr
## WebDevice

WebDevice is a read-only, HTTP-based filesystem in CheerpX. It's primarily used for accessing files from your web server.
[`WebDevice`](/docs/reference/CheerpX.WebDevice) is a read-only, HTTP-based filesystem in CheerpX. It's primarily used for accessing files from your web server.

### Usage

To create a WebDevice, use the `CheerpX.WebDevice.create()` method:
To [create](/docs/reference/CheerpX.WebDevice/create) a [`WebDevice`](/docs/reference/CheerpX.WebDevice), use the `CheerpX.WebDevice.create()` method:

```js
const webDevice = await CheerpX.WebDevice.create("path/to/local/directory");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: create
description: Create a CheerpX WebDevice instance, representing a read-only HTTP-based filesystem for CheerpX.
---

```ts
namespace CheerpX {
class WebDevice {
static async create(path: string): Promise<WebDevice>;
}
}
```

## Parameters

- **path (`string`)** - The path to the local directory you want to mount.

## Returns

`CheerpX.WebDevice.create` returns a [Promise] that gives you a `WebDevice` instance. You can use this instance to mount the specified directory in the CheerpX filesystem.

## Example

Create a `webDevice` instance for the `/webdevice` directory.

```js
// Add a device to expose a directory on the HTTP server in the VM
const webDevice = await CheerpX.WebDevice.create("/webdevice");

// Initialize the CheerpX environment
const mountPoints = [
// Mount the WebDevice to a known location
{ type: "dir", path: "/webdevice", dev: webDevice },
];
const cx = await CheerpX.Linux.create({
mounts: mountPoints,
});
```

For more information, please check out the [Files and File system guide](/docs/guides/File-System-support). This guide provides more details on how to work with files and directories in CheerpX.

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

0 comments on commit 6fe7c96

Please sign in to comment.