syncApp()
Sync a local folder to a remote server with efficient delta patching. Supports watch mode for continuous syncing on file changes. This function uses xdelta3 for binary delta compression, allowing efficient updates by only transmitting changed portions of files. It respects.gitignore patterns and provides filtering options.
Parameters
Path to the local folder to sync
Sync configuration options
The API URL of the sync server
Auth token for the server
Device or instance identifier - used only for local cache scoping
Directory for the client-side folder-sync cache. Used to store the last-synced “basis” copies of files (and related sync metadata) so we can compute xdelta patches on subsequent syncs without re-downloading server state.Can be absolute or relative to process.cwd().
Whether to install the app after syncing (iOS/Android only)
Launch mode for the app after installation
If true, watch the folder and re-sync on any changes (debounced, single-flight)
Max patch size (bytes) to send as delta before falling back to full upload. Default is 4MB.
Custom logging function
Optional filter function to include/exclude files and directories. Called with the relative path from localFolderPath (using forward slashes). For directories, the path ends with ’/’. Return true to include, false to exclude.
Returns
Examples
Delta Patching
The folder sync system uses xdelta3 for efficient binary delta compression. This significantly reduces network transfer by only sending changed portions of files.How it Works
- First Sync: All files are sent in full and cached locally in
basisCacheDir - Subsequent Syncs:
- Files are hashed (SHA-256) to detect changes
- For changed files, xdelta3 computes a binary patch against the cached basis
- If the patch is smaller than
maxPatchBytes, it’s sent as a delta - Otherwise, the full file is sent
- Server Side: The server applies patches to reconstruct the target files
- Cache Update: After successful sync, the local cache is updated
Benefits
- Reduced bandwidth: Only changes are transmitted
- Faster syncs: Less data to upload means quicker iterations
- Automatic fallback: Large patches automatically fall back to full upload
- No server state required: Client maintains basis cache locally
Requirements
- xdelta3 must be installed and available in PATH
- The system automatically checks for xdelta3 on first use
Watch Mode
Watch mode enables continuous syncing by monitoring the folder for changes.Features
- Debounced: Changes are debounced to avoid excessive syncs
- Single-flight: Only one sync runs at a time; changes queue up
- File system events: Uses native file system watchers for efficiency
- Graceful shutdown: Call
stopWatching()to cleanly stop monitoring
Behavior
- Initial sync happens immediately
- File system watcher starts monitoring the folder
- On file changes:
- If a sync is in progress, the change is queued
- Otherwise, a new sync starts immediately
- Multiple rapid changes are batched into a single sync
Filtering
The sync system provides multiple levels of filtering:1. Automatic Exclusions
Always excluded:.git/directories.DS_Storefiles- Files matching
.gitignorepatterns (if.gitignoreexists)
2. Custom Filter Function
Provide afilter function for fine-grained control:
- Called for every file and directory
relativePathuses forward slashes (/)- Directories end with
/ - Return
trueto include,falseto exclude
Examples
Types
FolderSyncOptions
SyncAppResult
Path where the app was installed (present only if install was enabled)
Bundle ID of the installed app (present only if install was enabled)
Function to stop watching for file changes (present only when watch=true)