file_management.rs — Persistent File Storage
Handles all file I/O for the application. Files are stored inside Tauri's app_data_dir, which is platform-specific (e.g. %APPDATA%\base_station on Windows). Three subdirectories are used:
Directory | Purpose |
| Saved task plan files |
| Snapshots captured from video feeds |
| Imported map files |
These directories are created automatically on startup by ensure_storage_dirs_internal().
Commands
save_task_file(file_name, data, directory) Writes raw bytes to a file in the given subdirectory. Used to persist task plans.
list_task_files(directory) → Vec<String> Returns a list of filenames in the given subdirectory. Returns an empty list if the directory doesn't exist yet.
read_task_file(file_name) → Vec<u8> Reads a file from the tasks/ directory and returns its raw bytes.
delete_one_file(directory, file_name) Deletes a single named file from the given subdirectory. Does nothing if the file doesn't exist.
delete_all_task_files(directory) Removes all files in a subdirectory by deleting and recreating it.
import_map_file(directory) Copies a file from an arbitrary path on the filesystem into the maps/ subdirectory. Used when the operator imports a new map via the file picker. The original filename is preserved.
save_snapshot(port, file_name) Captures a single JPEG frame from an MJPEG stream (given by its localhost URL/port) and saves it to the images/ directory as {file_name}.jpg. Used in the Science task to photograph samples. It scans the raw HTTP stream for the JPEG start marker (0xFF 0xD8) and end marker (0xFF 0xD9), extracting the first complete frame. Has a 5 MB safety limit per frame.
No comments to display
No comments to display