React Native Requires Chilkat v11.0.0+
React Native
Unzip Encrypted Text into a String Variable
See more Zip Examples
Demonstrates how to open an encrypted .zip archive and unzip a text file directly into a string variable.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();
// Set the password required for decrypting.
zip.decryptPassword = 'myPassword';
try {
await zip.openZipAsync('encrypted.zip');
} catch {
console.log(zip.lastErrorText);
return;
}
// Locate the file within the Zip to be unzipped into a string variable:
const entry = new ZipEntry();
try {
zip.entryMatching('*.csv', entry);
} catch {
console.log(zip.lastErrorText);
return;
}
// lineEndingBehavior:
// 0 = leave unchanged.
// 1 = convert all to bare LF's
// 2 = convert all to CRLF's
const lineEndingBehavior = 0;
const srcCharset = 'utf-8';
const strCsv = await entry.unzipToStringAsync(lineEndingBehavior, srcCharset);
console.log(strCsv);
}