Sample code for 30+ languages & platforms
React Native 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 React Native Downloads

React Native
import { Zip, ZipEntry } from '@chilkat/react-native'

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

  const zip = new Zip();

  // Open a .zip containing PEM files, among other things..
  try {
    await zip.openZipAsync('qa_data/certs/thawte-roots.zip');
  } catch {
    console.log(zip.lastErrorText);
    return;
  }

  const entry = new ZipEntry();
  let pemStr = '';
  const pattern = '*.pem';

  let bHasMoreMatches = true;
  try {
    zip.entryMatching(pattern, entry);
  } catch {
    bHasMoreMatches = false;
  }
  while (bHasMoreMatches) {

    console.log(`Entry: ${entry.fileName}`);

    // Get the uncommpressed contents of the entry:
    pemStr = await entry.unzipToStringAsync(0, 'utf-8');
    console.log(pemStr);

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