archiveTo method

Future<void> archiveTo(
  1. File target, {
  2. Iterable<FileLogSession>? sessions,
})

Packs the given sessions (all by default) into a single ZIP archive target. Inside the archive every session is a separate file <sessionId>.jsonl with the same content exportTo would produce. An existing target is overwritten.

Implementation

Future<void> archiveTo(
  File target, {
  Iterable<FileLogSession>? sessions,
}) async {
  final selected = sessions?.toList() ?? await list();

  final archive = Archive();
  for (final session in selected) {
    final builder = BytesBuilder(copy: false);
    await session.read().forEach(builder.add);
    archive
        .add(ArchiveFile.bytes('${session.id}.jsonl', builder.takeBytes()));
  }

  await target.parent.create(recursive: true);
  await target.writeAsBytes(ZipEncoder().encode(archive), flush: true);
}