startZip method

ZipJob startZip(
  1. XDropFile dir
)

Start compressing a dropped directory (dir with XDropFile.isDirectory) into <temp>/ux_drops/<uuid>/<folder>.zip for upload. A folder / macOS package can't be uploaded as a single file. On macOS native zips it (ZIPFoundation) off the main thread, re-acquiring access from dir's security-scoped bookmark, and streams a determinate fraction back over _control; on Windows zipFolder writes it in an isolate, reporting the fraction of bytes read.

Returns a ZipJob: bind a progress UI to ZipJob.progress, await ZipJob.result for the zip as an XDropFile marked XDropFile.isTemporaryCopy (promote into the cache after upload), and call ZipJob.cancel to abort. result is null when cancelled or unsupported (neither macOS nor Windows) and throws on a genuine zip failure — the caller sends nothing in either case, surfacing only the failure. A cancelled or failed zip leaves no per-drop directory behind.

Implementation

ZipJob startZip(XDropFile dir) {
  final id = 'zip${_zipSeq++}';
  final progress = ValueNotifier<double>(0);
  if (defaultTargetPlatform == TargetPlatform.windows) {
    final cancel = Completer<void>();
    return ZipJob._(
      id: id,
      progress: progress,
      result: _zipInDart(dir, progress, cancel.future),
      cancel: () {
        if (!cancel.isCompleted) cancel.complete();
      },
    );
  }
  _zipProgress[id] = progress;
  return ZipJob._(
    id: id,
    progress: progress,
    result: _runZip(id, dir),
    cancel: () => _cancelZip(id),
  );
}