Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

Iterate over Matching Filenames

See more Zip Examples

Iterates over files within a .zip that match a pattern. In this case, the pattern is "*.pem". This example will open a .zip containing files of type .txt, .cer, .pem, and possibly others, and will iterate over only the .pem files.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final zip = CkZip();

  // Open a .zip containing PEM files, among other things..
  try {
    zip.openZip('qa_data/certs/thawte-roots.zip');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final entry = CkZipEntry();
  var pemStr = '';
  final pattern = '*.pem';

  var bHasMoreMatches = true;
  try {
    zip.entryMatching(pattern, entry);
  } on ChilkatException {
    bHasMoreMatches = false;
  }
  while (bHasMoreMatches) {

    print('Entry: ${entry.fileName}');

    // Get the uncommpressed contents of the entry:
    pemStr = entry.unzipToString(0, 'utf-8');
    print(pemStr);

    bHasMoreMatches = true;
    try {
      entry.getNextMatch(pattern);
    } on ChilkatException {
      bHasMoreMatches = false;
    }
  }
}