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

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 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();

  // Set the password required for decrypting.
  zip.decryptPassword = 'myPassword';

  try {
    zip.openZip('encrypted.zip');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Locate the file within the Zip to be unzipped into a string variable:
  final entry = CkZipEntry();
  try {
    zip.entryMatching('*.csv', entry);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // lineEndingBehavior:
  // 0 = leave unchanged.
  // 1 = convert all to bare LF's
  // 2 = convert all to CRLF's
  final lineEndingBehavior = 0;
  final srcCharset = 'utf-8';

  final strCsv = entry.unzipToString(lineEndingBehavior, srcCharset);
  print(strCsv);
}