Dart Requires Chilkat v11.0.0+
Dart
Find a ZIP Entry by EntryID Using EntryById
See more Zip Examples
This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.
Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.
This is useful when:
- An application stores EntryID values for later use
- ZIP entries need to be retrieved without searching by filename
- Multiple entries may have similar names or paths
The example:
- Opens a ZIP archive
-
Retrieves an entry using
EntryAt -
Saves the entry's
EntryID -
Uses
EntryByIdto retrieve the same entry later
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Open an existing ZIP archive.
final zip = CkZip();
try {
zip.openZip('example.zip');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Retrieve the first entry in the ZIP archive.
final entry = CkZipEntry();
try {
zip.entryAt(0, entry);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Original entry:');
print(' FileName: ${entry.fileName}');
print(' EntryID: ${entry.entryID}');
print('');
// Save the EntryID for later use.
final entryId = entry.entryID;
// Create another ZipEntry object.
final entry2 = CkZipEntry();
// Retrieve the same entry using EntryById.
try {
zip.entryById(entryId, entry2);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Entry retrieved by EntryID:');
print(' FileName: ${entry2.fileName}');
print(' EntryID: ${entry2.entryID}');
print('');
// The filenames and EntryID values should match.
zip.closeZip();
print('Done.');
}