openArchiveFile function

Future<Archive> openArchiveFile(
  1. String path, {
  2. ArchiveFormatRegistry? registry,
  3. ArchiveFormat? format,
  4. ArchiveReadOptions options = const ArchiveReadOptions(),
})

Opens the archive file at path, auto-detecting its format.

Sugar for Archive.open over a FileByteSource. (A static Archive.openFile is impossible without pulling dart:io into the platform-neutral main library, hence a top-level function; see doc/notes.md.) The file is closed if opening fails.

Implementation

Future<Archive> openArchiveFile(
  String path, {
  ArchiveFormatRegistry? registry,
  ArchiveFormat? format,
  ArchiveReadOptions options = const ArchiveReadOptions(),
}) async {
  final source = await FileByteSource.open(path);
  try {
    return await Archive.open(
      source,
      registry: registry,
      format: format,
      options: options,
    );
  } catch (_) {
    await source.close();
    rethrow;
  }
}