Save and serialize designs in CE.SDK for later retrieval, sharing, or storage using string or archive formats.
CE.SDK provides two formats for persisting designs. Choose the format based on your storage and portability requirements.
Save Format Comparison#
| Format | Method | Assets | Best For |
|---|---|---|---|
| String | saveToString() | Referenced by URL | Database storage, cloud sync |
| Archive | saveToArchive() | Embedded in ZIP | Offline use, file sharing |
String format produces a lightweight serialized string where assets remain as URL references. Use this when asset URLs will remain accessible.
Archive format creates a self-contained ZIP with all assets embedded. Use this for portable designs that work offline.
Save to String#
Serialize the current scene to a string suitable for database storage.
let sceneString = try await engine.scene.saveToString()The string contains the complete scene structure but references assets by their original URLs.
Save to Archive#
Create a self-contained ZIP with the scene and all embedded assets.
let archiveBlob = try await engine.scene.saveToArchive()saveToArchive() returns a Blob (a Data value) that includes all pages, elements, and asset data in a single portable file.
Compression Options#
CE.SDK supports optional compression for saved scenes to reduce file size. Compression is particularly useful for large scenes or when storage space is limited.
let compressed = try await engine.scene.saveToString( options: SaveToStringOptions( compression: CompressionOptions(format: .zstd, level: .default), ),)Compression Formats:
CompressionFormat.none— No compression (default)CompressionFormat.zstd— Zstandard compression (recommended for best performance)
Compression Levels:
CompressionLevel.fastest— Fastest compression, larger outputCompressionLevel.default— Balanced speed and size (recommended)CompressionLevel.best— Best compression, slower
Compression adds minimal overhead while reducing scene size by approximately 64%. The default level provides the best balance of speed and compression ratio.
Write to Disk#
Use Foundation’s file APIs to persist saved designs to the file system.
Scene strings can be written directly as text:
let sceneURL = outputDir.appendingPathComponent("scene.scene")try sceneString.write(to: sceneURL, atomically: true, encoding: .utf8)Archives are returned as Data, which writes to disk in a single call:
let archiveURL = outputDir.appendingPathComponent("scene.zip")try archiveBlob.write(to: archiveURL)Load Scene from File#
Read a previously saved .scene file from disk and restore it to the engine with engine.scene.load(from:).
let restoredString = try String(contentsOf: sceneURL, encoding: .utf8)try await engine.scene.load(from: restoredString)Scene files are lightweight but require the original asset URLs to remain accessible.
Load Archive from File#
Use engine.scene.loadArchive(from:) with a local file URL to restore a self-contained .zip archive that includes all embedded assets.
try await engine.scene.loadArchive(from: archiveURL)Archives are portable and work offline since all assets are bundled within the file.
API Reference#
| Method | Description |
|---|---|
engine.scene.saveToString() | Serialize scene to string with optional compression |
engine.scene.saveToArchive() | Save scene with assets as ZIP Data |
engine.scene.load(from:) | Load scene from a serialized string or remote URL |
engine.scene.loadArchive(from:) | Load scene from a ZIP archive URL (local file or remote) |
engine.block.saveToString() | Serialize specific blocks to a string |
engine.block.saveToArchive(blocks:) | Save specific blocks with assets as ZIP Data |
engine.block.load(from:) | Load blocks from a serialized string or URL |
engine.block.loadArchive(from:) | Load blocks from a ZIP archive URL |
Next Steps#
- Export Overview — Export designs to image, PDF, and video formats
- Load Scene — Load scenes from remote URLs and archives
- Store Custom Metadata — Attach metadata like tags or version info to designs
- Partial Export — Export individual blocks or selections