Skip to content

Commit 9b81d1f

Browse files
committed
Added text
1 parent 9acbd9a commit 9b81d1f

File tree

1 file changed

+37
-1
lines changed
  • sites/cheerpx/src/content/docs/12-reference/CheerpX.OverlayDevice

1 file changed

+37
-1
lines changed

sites/cheerpx/src/content/docs/12-reference/CheerpX.OverlayDevice/create.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: create
3-
description: Virtual filesystems and how to use them
3+
description: Create a writable persistent overlay device on top of another block device.
44
---
55

66
```ts
@@ -16,3 +16,39 @@ namespace CheerpX {
1616
- **baseDevice (`Device`)** - The underlying device (e.g., `HttpBytesDevice`, `IDBDevice`) that serves as the base layer for the filesystem.
1717

1818
- **overlayDevice (`Device`)** - The writable layer that will overlay the base device, enabling persistent changes.
19+
20+
## Returns
21+
22+
`CheerpX.OverlayDevice.create` returns a [Promise] that resolves to an instance of the `OverlayDevice`. The `OverlayDevice` allows you to overlay a writable layer on top of the base device, enabling persistent changes while still accessing the base data.
23+
24+
## Example
25+
26+
Create an `OverlayDevice` instance to combine a `HttpBytesDevice` for streaming data from an HTTP source and an `IDBDevice` for caching and persistent local storage.
27+
28+
```ts {8, 12}
29+
// Create a read-only HttpBytesDevice for streaming disk blocks via HTTP
30+
const httpDevice = await CheerpX.HttpBytesDevice.create("/cheerpXImage.ext2");
31+
32+
// Create an IDBDevice for local persistent storage
33+
const idbDevice = await CheerpX.IDBDevice.create("block_idbDevice");
34+
35+
// Create an OverlayDevice to combine the two devices
36+
const overlayDevice = await CheerpX.OverlayDevice.create(httpDevice, idbDevice);
37+
38+
// Mount the overlay device in the CheerpX environment as an ext2 filesystem
39+
const cx = await CheerpX.Linux.create({
40+
mounts: [{ type: "ext2", path: "/", dev: overlayDevice }],
41+
});
42+
```
43+
In this example, the `OverlayDevice` provides a writable layer on top of the `HttpBytesDevice` (which serves as a read-only block device for streaming), allowing changes to be stored locally via the `IDBDevice`.
44+
45+
<!-- Add links when rest of the references are added -->
46+
<!-- ## Related sources
47+
48+
- [Cheerp.HttpBytesDevice.create]()
49+
- [Cheerp.IDBDevice.create]()
50+
- [Cheerp.Linux.create]() -->
51+
52+
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.
53+
54+
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

0 commit comments

Comments
 (0)