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

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 EntryById to retrieve the same entry later

Chilkat React Native Downloads

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

async function chilkatExample() {
  // Open an existing ZIP archive.
  const zip = new Zip();

  try {
    await zip.openZipAsync('example.zip');
  } catch {
    console.log(zip.lastErrorText);
    return;
  }

  // Retrieve the first entry in the ZIP archive.
  const entry = new ZipEntry();

  try {
    zip.entryAt(0, entry);
  } catch {
    console.log(zip.lastErrorText);
    return;
  }

  console.log('Original entry:');
  console.log(`  FileName: ${entry.fileName}`);
  console.log(`  EntryID: ${entry.entryID}`);
  console.log('');

  // Save the EntryID for later use.
  const entryId = entry.entryID;

  // Create another ZipEntry object.
  const entry2 = new ZipEntry();

  // Retrieve the same entry using EntryById.
  try {
    zip.entryById(entryId, entry2);
  } catch {
    console.log(zip.lastErrorText);
    return;
  }

  console.log('Entry retrieved by EntryID:');
  console.log(`  FileName: ${entry2.fileName}`);
  console.log(`  EntryID: ${entry2.entryID}`);
  console.log('');

  // The filenames and EntryID values should match.
  zip.closeZip();

  console.log('Done.');
}