create
Create a CheerpX DataDevice instance to store temporary data in memory.
namespace CheerpX { class DataDevice { static async create(): Promise<DataDevice>; }}
Parameters
- None
Returns
CheerpX.DataDevice.create
returns a Promise that resolves to a
DataDevice
instance. You can use this instance to create a temporary in-memory filesystem in your CheerpX environment.
Example
Create a DataDevice
instance for in-memory storage.
// Create a read-only block device for a disk image stored on the HTTP serverconst blockDevice = await CheerpX.HttpBytesDevice.create("/cheerpXImage.ext2");// Make the block device read-write using a persistent IndexedDB overlayconst idbDevice = await CheerpX.IDBDevice.create("block_idbDevice");const overlayDevice = await CheerpX.OverlayDevice.create( blockDevice, idbDevice);// Add a device to expose JavaScript data in the VMconst dataDevice = await CheerpX.DataDevice.create();// Initialize the CheerpX environmentconst mountPoints = [ // Use the disk image as the filesystem root { type: "ext2", path: "/", dev: overlayDevice }, // Add the DataDevice to a known location { type: "dir", path: "/data", dev: dataDevice },];const cx = await CheerpX.Linux.create({ mounts: mountPoints,});
In this example, the DataDevice
is created using CheerpX.DataDevice.create()
and mounted at /data
in the Linux environment inside the CheerpX system.
If you’d like to learn more about related topics, check out these guides:
- Files and filesystems – Managing files and storage in CheerpX.
- Custom disk images – Creating and using custom disk images.
- Input and output – Handling data flow in your environment.