React Native Requires Chilkat v11.0.0+
React Native
Unzip Selected Files from a Zip Archive
See more Zip Examples
Demonstrates how to iterate over the files contained within a .zip and unzip specific files.Chilkat React Native Downloads
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();
try {
await zip.openZipAsync('my_files.zip');
} catch {
console.log(zip.lastErrorText);
return;
}
const unzipDir = '/temp/unzipDir';
// Get the number of files and directories in the .zip
const n = zip.numEntries;
const entry = new ZipEntry();
let i = 0;
while (i < n) {
zip.entryAt(i, entry);
if (!entry.isDirectory) {
// (the filename may include a path)
console.log(entry.fileName);
// Your application may choose to unzip this entry
// based on the filename.
// If the entry should be unzipped, then call Extract(unzipDir)
try {
await entry.extractAsync(unzipDir);
} catch {
console.log(entry.lastErrorText);
return;
}
}
i++;
}
}