ZIP archives
suggest changeThe Dart SDK can compress a single stream with gzip or zlib (dart:io has gzip and zlib codecs), but it can't read or write ZIP archives. For that, use package:archive. It's pure Dart, so it works on the server, in command-line tools, in Flutter apps and on the web.
It handles:
- ZIP, including zip64 for files over 4 GB and AES-encrypted (password-protected) archives
- tar, plain or compressed with gzip, bzip2, xz or zstd
- the gzip, zlib, bzip2, xz and zstd codecs on their own
Add it to your project:
dart pub add archive
This adds a dependency like archive: ^4.5.2. The examples here use the 4.x API. Version 4 changed many names from 3.x (ArchiveFile.string and content replaced ArchiveFile(name, size, data) and content as List<int>, encodeBytes replaced encode), so older answers on the web often won't compile.
The package has two libraries:
| Import | Contains | Platforms |
|---|---|---|
package:archive/archive.dart |
Archive, ArchiveFile, ZipEncoder, ZipDecoder, the codecs, in-memory streams |
all, including web |
package:archive/archive_io.dart |
everything above, plus file streams, ZipFileEncoder, extractFileToDisk |
dart:io only |
The model: Archive and ArchiveFile
An Archive is a list of ArchiveFile entries. Each entry has a name (a path that uses /), content, a modification time and Unix permissions. You build an Archive and pass it to an encoder, or get one back from a decoder. The same model is used for zip and tar.
Creating a ZIP in memory
Make entries with ArchiveFile.string, ArchiveFile.bytes or ArchiveFile.directory, add them to an Archive, and encode it with ZipEncoder:
import 'dart:io';
import 'dart:typed_data';
import 'package:archive/archive.dart';
void main() {
final archive = Archive()
..add(ArchiveFile.string('hello.txt', 'Hello, ZIP!\n'))
..add(ArchiveFile.string('docs/readme.md', '# Readme\n' * 100))
..add(
ArchiveFile.bytes(
'data/numbers.bin',
Uint8List.fromList(List.generate(256, (i) => i)),
),
)
..add(ArchiveFile.directory('empty/'));
final Uint8List zipBytes = ZipEncoder().encodeBytes(archive);
File('out.zip').writeAsBytesSync(zipBytes);
print('wrote out.zip: ${zipBytes.length} bytes');
}
Output:
wrote out.zip: 713 bytes
A few things to know:
- Use
/in entry names, even on Windows. Folders are implied by the names (docs/readme.md), so you only needArchiveFile.directoryfor empty folders. - Each entry's modification time defaults to now. Set
lastModTime(seconds since the epoch) if you need something else, or passmodified:toencodeBytesto use one time for every entry. A fixed time makes builds reproducible. encodeBytesbuilds the whole zip in memory. For large archives, write straight to a file withZipFileEncoderorencodeStream(shown below).
The result is a normal zip file:
$ unzip -l out.zip
Archive: out.zip
Length Date Time Name
--------- ---------- ----- ----
12 2026-10-17 21:50 hello.txt
900 2026-10-17 21:50 docs/readme.md
256 2026-10-17 21:50 data/numbers.bin
0 2026-10-17 21:50 empty/
--------- -------
1168 4 files
Reading a ZIP
ZipDecoder().decodeBytes turns bytes into an Archive. It's an Iterable<ArchiveFile>, so you can loop over it, and find looks up an entry by name:
import 'dart:convert';
import 'dart:io';
import 'package:archive/archive.dart';
void main() {
final bytes = File('out.zip').readAsBytesSync();
final archive = ZipDecoder().decodeBytes(bytes);
for (final entry in archive) {
final kind = entry.isFile ? 'file' : 'dir ';
final size = entry.size.toString().padLeft(4);
print('$kind ${entry.name.padRight(18)} $size bytes'
' ${entry.compression?.name}');
}
final hello = archive.find('hello.txt');
if (hello != null) {
print('hello.txt says: ${utf8.decode(hello.content).trim()}');
}
print('missing: ${archive.find('nope.txt')}');
}
Output:
file hello.txt 12 bytes deflate
file docs/readme.md 900 bytes deflate
file data/numbers.bin 256 bytes deflate
dir empty/ 0 bytes none
hello.txt says: Hello, ZIP!
missing: null
entry.content is a Uint8List with the uncompressed data. It's decompressed the first time you read it, not when the archive is decoded, so listing a zip is cheap. entry.size is the uncompressed size as recorded in the zip.
Reading from a file without loading it
decodeBytes needs the whole zip in memory. For a big file, open it with InputFileStream and use decodeStream. It reads the zip's central directory (the table of contents at the end of the file) and seeks to each entry's data only when you ask for it:
import 'package:archive/archive_io.dart';
Future<void> main() async {
final input = InputFileStream('out.zip');
try {
final archive = ZipDecoder().decodeStream(input);
for (final entry in archive.where((e) => e.isFile)) {
final modified = entry.lastModDateTime;
print('${entry.name}: ${entry.size} bytes, modified ${modified.year}');
}
// Content is read and decompressed when you ask for it.
final readme = archive.find('docs/readme.md')!;
print('first line: ${String.fromCharCodes(readme.content.take(8))}');
} finally {
await input.close();
}
}
Output:
hello.txt: 12 bytes, modified 2026
docs/readme.md: 900 bytes, modified 2026
data/numbers.bin: 256 bytes, modified 2026
first line: # Readme
Close the stream when you're done. Until then the file stays open, and on Windows you can't delete or replace it.
Extracting to disk
extractFileToDisk from archive_io.dart does the whole job: it opens the file, creates folders, writes files and sets permissions. It picks the format from the extension (.zip, .tar, .tar.gz, .tgz, .tar.bz2, .tar.xz, .tar.zst):
import 'dart:io';
import 'package:archive/archive_io.dart';
Future<void> main() async {
final outDir = Directory('extracted');
if (outDir.existsSync()) outDir.deleteSync(recursive: true);
await extractFileToDisk('out.zip', outDir.path);
final entries = outDir.listSync(recursive: true)
..sort((a, b) => a.path.compareTo(b.path));
for (final f in entries) {
final type = f is Directory ? 'dir ' : 'file';
print('$type ${f.path.replaceAll(r'\', '/')}');
}
}
Output:
dir extracted/data
file extracted/data/numbers.bin
dir extracted/docs
file extracted/docs/readme.md
dir extracted/empty
file extracted/hello.txt
If you already have an Archive (for example decoded from bytes you downloaded), use extractArchiveToDisk(archive, path) instead. Both accept password: (only extractFileToDisk) and maxSize:.
Untrusted archives: zip slip and zip bombs
When the zip comes from a user or the internet, two attacks matter:
- Zip slip. An entry named
../../.bashrcwould be written outside the output folder. - Zip bomb. A small zip that expands to gigabytes and fills the disk or memory.
extractFileToDisk and extractArchiveToDisk skip entries whose path (or symlink target) points outside the output folder. Limit the total size with maxSize:
import 'dart:io';
import 'dart:typed_data';
import 'package:archive/archive_io.dart';
Future<void> main() async {
// A malicious archive: entry names that try to escape the target folder.
final evil = Archive()
..add(ArchiveFile.string('ok.txt', 'fine'))
..add(ArchiveFile.string('../escaped.txt', 'gotcha'))
..add(ArchiveFile.string('sub/../../escaped2.txt', 'gotcha'));
File('evil.zip').writeAsBytesSync(ZipEncoder().encodeBytes(evil));
final out = Directory('safe-out')..createSync();
await extractFileToDisk('evil.zip', out.path);
final names = out.listSync().map((e) => e.uri.pathSegments.last).toList();
print('in safe-out: $names');
print('escaped.txt exists: ${File('escaped.txt').existsSync()}');
// A zip bomb: 200 MB of zeros compresses to about 200 KB.
final bomb = Archive()
..add(ArchiveFile.bytes('zeros.bin', Uint8List(200 * 1024 * 1024)));
File('bomb.zip').writeAsBytesSync(
ZipEncoder().encodeBytes(bomb, level: DeflateLevel.bestCompression),
);
print('bomb.zip: ${File('bomb.zip').lengthSync()} bytes');
try {
await extractFileToDisk('bomb.zip', 'bomb-out', maxSize: 50 * 1024 * 1024);
} on ArchiveException catch (e) {
print('refused: ${e.message}');
}
}
Output:
in safe-out: [ok.txt]
escaped.txt exists: false
bomb.zip: 203958 bytes
refused: Extracting the archive would write more than 52428800 bytes
The path checks were tightened and maxSize was added in archive 4.5.0, so require at least ^4.5.0 if you rely on them.
Extracting entries yourself
When you write entries out yourself, for example to keep only some files, you have to do those checks yourself. package:path (dart pub add path) gives you canonicalize and isWithin. Sizes come from the zip's directory, so you can reject an archive before decompressing anything:
import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:path/path.dart' as p;
/// Extracts only `.md` files, refusing unsafe names and oversized archives.
Future<void> extractMarkdown(
String zipPath,
String outDir, {
int maxTotal = 10 << 20,
}) async {
final root = p.canonicalize(outDir);
final input = InputFileStream(zipPath);
try {
final archive = ZipDecoder().decodeStream(input);
final total = archive.fold<int>(0, (sum, e) => sum + e.size);
if (total > maxTotal) {
throw ArchiveException(
'archive expands to $total bytes, limit is $maxTotal',
);
}
for (final entry in archive) {
if (!entry.isFile || p.extension(entry.name) != '.md') continue;
final dest = p.canonicalize(p.join(root, entry.name));
if (!p.isWithin(root, dest)) {
print('skipping unsafe entry ${entry.name}');
continue;
}
await Directory(p.dirname(dest)).create(recursive: true);
final output = OutputFileStream(dest);
entry.writeContent(output); // streams, without loading it all in memory
await output.close();
print('extracted ${entry.name}');
}
} finally {
await input.close();
}
}
Future<void> main() async {
await extractMarkdown('out.zip', 'md-only');
try {
await extractMarkdown('bomb.zip', 'md-only');
} on ArchiveException catch (e) {
print(e.message);
}
}
Output:
extracted docs/readme.md
archive expands to 209715200 bytes, limit is 10485760
The sizes in the directory are written by whoever made the zip. The decoder never decompresses an entry past its declared size (since 4.5.0), so a lying header produces a short file, not an unbounded one.
Zipping a folder
ZipFileEncoder writes straight to a file, reading each input file as it goes, so memory use stays low. zipDirectory zips a whole folder in one call. For more control, create a zip and add folders, files and in-memory entries one at a time:
import 'dart:io';
import 'package:archive/archive_io.dart';
Future<void> main() async {
// Build a small project tree to zip.
final dir = Directory('project');
if (dir.existsSync()) dir.deleteSync(recursive: true);
File('project/lib/main.dart')
..createSync(recursive: true)
..writeAsStringSync('void main() => print("hi");\n');
File('project/README.md').writeAsStringSync('# Project\n');
File('project/build/app.exe')
..createSync(recursive: true)
..writeAsBytesSync(List.filled(4096, 0));
File('project/.env').writeAsStringSync('SECRET=1\n');
// One call: zips the contents of project/ into project.zip.
await ZipFileEncoder().zipDirectory(dir, filename: 'project.zip');
printEntries('project.zip');
// More control: choose names inside the zip and skip some files.
final encoder = ZipFileEncoder()..create('source.zip');
await encoder.addDirectory(
dir,
includeDirName: false,
filter: (entity, progress) {
final path = entity.path.replaceAll(r'\', '/');
if (path.contains('/build') || path.endsWith('/.env')) {
return ZipFileOperation.skip;
}
return ZipFileOperation.include;
},
);
await encoder.addFile(File('pubspec.yaml'), 'meta/pubspec.yaml');
encoder.addArchiveFile(ArchiveFile.string('VERSION', '1.0.0\n'));
await encoder.close();
printEntries('source.zip');
}
void printEntries(String zipPath) {
final archive = ZipDecoder().decodeBytes(File(zipPath).readAsBytesSync());
final names = archive.map((e) => e.name).toList()..sort();
print('$zipPath: $names');
}
Output:
project.zip: [.env, README.md, build/, build/app.exe, lib/, lib/main.dart]
source.zip: [README.md, VERSION, lib/, lib/main.dart, meta/pubspec.yaml]
Notes:
zipDirectorydoesn't include the folder name in entry paths. WithaddDirectory,includeDirNamedefaults totrue, which puts everything underproject/.- The
filtercallback returnsinclude,skiporcancelfor each file and folder. Itsprogressargument goes from 0 to 1, which you can show in a UI. There's also anonProgresscallback. - Always call
close(). It writes the central directory at the end of the file. Without it the zip is unreadable. ZipFileEncoderconverts Windows\separators to/for you.
Compression level and stored entries
ZIP entries are usually compressed with deflate. The level goes from DeflateLevel.none (0) to DeflateLevel.bestCompression (9). ZipEncoder.encodeBytes defaults to DeflateLevel.bestSpeed (1), which is fast and usually close to the best:
import 'dart:math';
import 'dart:typed_data';
import 'package:archive/archive.dart';
void main() {
// Text compresses well; random bytes (like JPEG or PNG data) don't.
final text = List.generate(
5000,
(i) => 'line $i: the quick brown fox\n',
).join();
final rnd = Random(42);
final noise = Uint8List.fromList(
List.generate(100000, (_) => rnd.nextInt(256)),
);
ArchiveFile textFile() => ArchiveFile.string('log.txt', text);
for (final (name, level) in [
('none', DeflateLevel.none),
('bestSpeed', DeflateLevel.bestSpeed),
('default', DeflateLevel.defaultCompression),
('best', DeflateLevel.bestCompression),
]) {
final zip = ZipEncoder().encodeBytes(
Archive()..add(textFile()),
level: level,
);
print('${name.padRight(10)} ${zip.length} bytes (text is ${text.length})');
}
// Store already-compressed data instead of wasting time deflating it.
final photo = ArchiveFile.bytes('photo.jpg', noise)
..compression = CompressionType.none;
final log = textFile()..compressionLevel = DeflateLevel.bestCompression;
final mixed = ZipEncoder().encodeBytes(
Archive()
..add(photo)
..add(log),
);
for (final e in ZipDecoder().decodeBytes(mixed)) {
print('${e.name}: ${e.compression!.name}');
}
}
Output:
none 154017 bytes (text is 153890)
bestSpeed 12924 bytes (text is 153890)
default 12900 bytes (text is 153890)
best 12875 bytes (text is 153890)
photo.jpg: none
log.txt: deflate
Set compression = CompressionType.none on entries that are already compressed (JPEG, PNG, MP4, other zips). Deflating them costs CPU and saves nothing. Some formats built on zip require a stored entry: EPUB and OpenDocument files must start with an uncompressed mimetype entry.
compressionLevel sets the level for one entry. CompressionType.bzip2 and CompressionType.zstd also exist, but many zip tools (including Windows Explorer) can't open them, so stick to deflate for files you share.
Password-protected ZIPs
Pass password to the encoder and the decoder. The encoder uses AES-256, which 7-Zip, WinZip and most modern tools can open (Windows Explorer can't):
import 'dart:convert';
import 'dart:io';
import 'package:archive/archive.dart';
void main() {
final archive = Archive()
..add(ArchiveFile.string('secret.txt', 'launch code: 1234'));
final zip = ZipEncoder(password: 'correct horse').encodeBytes(archive);
File('secret.zip').writeAsBytesSync(zip);
final ok = ZipDecoder().decodeBytes(zip, password: 'correct horse');
print(utf8.decode(ok.first.content));
for (final password in [null, 'wrong']) {
try {
final a = ZipDecoder().decodeBytes(zip, password: password);
print('decoded the directory, ${a.length} entry');
a.first.content; // decryption happens here
} on ArchiveException catch (e) {
print('password $password: ${e.message}');
}
}
}
Output:
launch code: 1234
decoded the directory, 1 entry
password null: A password is needed for the encrypted entry secret.txt
decoded the directory, 1 entry
password wrong: Wrong password for the encrypted entry
A wrong password isn't detected when you decode the archive, only when you read an entry's content. File names aren't encrypted, only the content. ZipFileEncoder(password: ...) and extractFileToDisk(..., password: ...) work the same way.
The decoder also reads the old ZipCrypto encryption, but that is easy to break. Don't rely on it for anything sensitive. For real protection, encrypt the data yourself (see Cryptography).
Modifying an existing ZIP
ZIP files can't be edited in place. You decode the archive, change the list of entries and write a new file. Adding an entry with a name that already exists replaces it:
import 'dart:convert';
import 'dart:io';
import 'package:archive/archive_io.dart';
Future<void> main() async {
final input = InputFileStream('out.zip');
final archive = ZipDecoder().decodeStream(input);
// Replace one entry (same name), remove one, add one.
archive.add(ArchiveFile.string('hello.txt', 'Hello again!\n'));
archive.removeFile(archive.find('data/numbers.bin')!);
archive.add(ArchiveFile.string('CHANGES.txt', 'updated\n'));
// Write to a new file: entries are still being read from out.zip.
final output = OutputFileStream('out-new.zip');
ZipEncoder().encodeStream(archive, output);
await output.close();
await input.close();
File('out-new.zip').renameSync('out.zip');
final updated = ZipDecoder().decodeBytes(File('out.zip').readAsBytesSync());
print(updated.map((e) => e.name).toList());
print(utf8.decode(updated.find('hello.txt')!.content).trim());
}
Output:
[hello.txt, docs/readme.md, empty/, CHANGES.txt]
Hello again!
Entries you don't touch are copied in their compressed form, without being decompressed and compressed again, so this is fast even for big archives.
Serving and downloading ZIPs over HTTP
A server often builds a zip on the fly, for example to let users download several files at once. Set Content-Type: application/zip and Content-Disposition so the browser saves it with a sensible name. On the other side, decode the downloaded bytes directly, without saving them to disk:
import 'dart:io';
import 'dart:typed_data';
import 'package:archive/archive.dart';
Future<void> main() async {
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
server.listen((request) {
// Build a report zip on the fly.
final archive = Archive()
..add(ArchiveFile.string('report.csv', 'id,total\n1,10\n2,20\n'))
..add(ArchiveFile.string('summary.txt', 'total: 30\n'));
final zip = ZipEncoder().encodeBytes(archive);
request.response
..headers.contentType = ContentType('application', 'zip')
..headers.set('Content-Disposition', 'attachment; filename="report.zip"')
..contentLength = zip.length
..add(zip)
..close();
});
// Download it and look inside, without touching the disk.
final client = HttpClient();
final request = await client.getUrl(
Uri.parse('http://localhost:${server.port}/report'),
);
final response = await request.close();
final builder = await response.fold(BytesBuilder(), (b, chunk) => b..add(chunk));
final bytes = builder.takeBytes();
print('${response.headers.contentType}, ${bytes.length} bytes');
print(response.headers.value('content-disposition'));
final archive = ZipDecoder().decodeBytes(bytes);
for (final f in archive) {
final text = String.fromCharCodes(f.content).trim().replaceAll('\n', ' | ');
print('${f.name}: $text');
}
client.close();
await server.close();
}
Output:
application/zip, 249 bytes
attachment; filename="report.zip"
report.csv: id,total | 1,10 | 2,20
summary.txt: total: 30
For accepting zips that users upload, see File uploads, and treat the archive as untrusted (zip slip, zip bombs) as described above.
Detecting corrupt or non-ZIP input
ZipDecoder is lenient. Given something that isn't a zip, or a truncated file, it returns an empty Archive instead of throwing. It also doesn't check each entry's CRC-32 checksum, so damaged data can come back without an error. If you need to be strict, check the magic bytes and the CRCs yourself:
import 'dart:io';
import 'dart:typed_data';
import 'package:archive/archive.dart';
// Zip files start with the local file header signature "PK\x03\x04".
bool looksLikeZip(List<int> b) =>
b.length >= 4 && b[0] == 0x50 && b[1] == 0x4b && b[2] == 0x03 && b[3] == 0x04;
/// Decodes a zip, rejecting non-zip input and entries whose CRC doesn't match.
Archive decodeZipStrict(List<int> bytes) {
if (!looksLikeZip(bytes)) {
throw ArchiveException('not a zip file');
}
final archive = ZipDecoder().decodeBytes(bytes);
if (archive.isEmpty) {
throw ArchiveException('no entries found (truncated?)');
}
for (final entry in archive.where((e) => e.isFile)) {
if (getCrc32(entry.content) != entry.crc32) {
throw ArchiveException('CRC mismatch in ${entry.name}');
}
}
return archive;
}
void main() {
final good = File('out.zip').readAsBytesSync();
final damaged = Uint8List.fromList(good)..[41] ^= 0x01; // in hello.txt data
final inputs = {
'good': good,
'text file': Uint8List.fromList('not a zip at all'.codeUnits),
'truncated': Uint8List.sublistView(good, 0, good.length ~/ 2),
'damaged': damaged,
};
print('ZipDecoder alone:');
for (final MapEntry(:key, :value) in inputs.entries) {
try {
final archive = ZipDecoder().decodeBytes(value);
for (final e in archive) {
e.content; // force decompression
}
print(' $key: ${archive.length} entries');
} on ArchiveException catch (e) {
print(' $key: ${e.message}');
}
}
print('decodeZipStrict:');
for (final MapEntry(:key, :value) in inputs.entries) {
try {
print(' $key: ${decodeZipStrict(value).length} entries');
} on ArchiveException catch (e) {
print(' $key: ${e.message}');
}
}
}
Output:
ZipDecoder alone:
good: 4 entries
text file: 0 entries
truncated: 0 entries
damaged: 4 entries
decodeZipStrict:
good: 4 entries
text file: not a zip file
truncated: no entries found (truncated?)
damaged: CRC mismatch in hello.txt
The magic-bytes check rejects two valid but rare cases: an empty zip (which starts with PK\x05\x06) and a self-extracting .exe with a zip appended. Relax it if you need those. Errors the decoder does detect are thrown as ArchiveException, which is a subclass of FormatException.
Keeping the UI or server responsive
Compression is CPU work, and every API in the package is synchronous underneath, even the ones that return a Future. Zipping a big folder blocks the isolate it runs on: a Flutter app freezes, a server stops answering requests. Run it in another isolate with Isolate.run:
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
import 'package:archive/archive_io.dart';
Future<void> main() async {
// Something to compress: 300 files of text.
final dir = Directory('many');
if (!dir.existsSync()) {
for (var i = 0; i < 300; i++) {
File('many/file$i.txt')
..createSync(recursive: true)
..writeAsStringSync('row $i\n' * 20000);
}
}
// Count timer ticks on the main isolate to show it stays responsive.
var ticks = 0;
final timer = Timer.periodic(
const Duration(milliseconds: 10),
(_) => ticks++,
);
final sw = Stopwatch()..start();
// Isolate.run copies the result back, so return something small.
final size = await Isolate.run(() {
final encoder = ZipFileEncoder()..create('many.zip');
encoder.addDirectorySync(Directory('many'), includeDirName: false);
encoder.closeSync();
return File('many.zip').lengthSync();
});
timer.cancel();
print('many.zip: $size bytes');
print('main isolate ticked $ticks times in ${sw.elapsedMilliseconds} ms');
}
Output (timing varies):
many.zip: 109445 bytes
main isolate ticked 62 times in 909 ms
The timer keeps firing while the zip is written, which wouldn't happen if the work ran on the main isolate. Pass paths into the isolate and return small results. Sending a large Uint8List between isolates copies it. See Isolates for more.
ZIP or gzip?
A zip holds many files with names. gzip compresses one stream of bytes, with no file list. If you only need to compress a single file or an HTTP body, you don't need a package: dart:io has gzip (and zlib) built in, backed by the native zlib library:
import 'dart:convert';
import 'dart:io';
Future<void> main() async {
final text = 'hello gzip\n' * 1000;
// In memory.
final compressed = gzip.encode(utf8.encode(text));
print('${text.length} -> ${compressed.length} bytes');
print(utf8.decode(gzip.decode(compressed)) == text);
// Streaming a file through the codec.
await File('big.txt').writeAsString(text);
await File('big.txt')
.openRead()
.transform(gzip.encoder)
.pipe(File('big.txt.gz').openWrite());
print('big.txt.gz: ${File('big.txt.gz').lengthSync()} bytes');
}
Output:
11000 -> 71 bytes
true
big.txt.gz: 71 bytes
On the web, where dart:io isn't available, use GZipEncoder and GZipDecoder from package:archive. For a folder in Unix-style distributions, the usual format is .tar.gz: TarFileEncoder from archive_io.dart creates one, and extractFileToDisk extracts it.
Summary
| Task | Code |
|---|---|
| Create entries | ArchiveFile.string(name, text), ArchiveFile.bytes(name, bytes), ArchiveFile.directory('dir/') |
| Encode to bytes | ZipEncoder().encodeBytes(archive) |
| Decode bytes | ZipDecoder().decodeBytes(bytes) |
| Decode a big file | ZipDecoder().decodeStream(InputFileStream(path)), then close() |
| Read an entry | archive.find('a.txt')?.content |
| Extract to a folder | await extractFileToDisk('a.zip', 'out', maxSize: limit) |
| Zip a folder | await ZipFileEncoder().zipDirectory(Directory('src'), filename: 'src.zip') |
| Build a zip file piece by piece | ZipFileEncoder()..create(path), addFile, addDirectory, addArchiveFile, close() |
| Don't compress an entry | entry.compression = CompressionType.none |
| Compression level | encodeBytes(archive, level: DeflateLevel.bestCompression) |
| Password (AES-256) | ZipEncoder(password: p), ZipDecoder().decodeBytes(b, password: p) |
| Verify integrity | getCrc32(entry.content) == entry.crc32 |
| Off the main isolate | await Isolate.run(() => ...) |