Dart Requires Chilkat v11.0.0+
Dart
Replace/Update a FIle in a .zip
See more Zip Examples
Demonstrates how to replace/update a file from a .zip. Note: This requires the entire .zip to be rewritten.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This requires the Chilkat Zip API to have been previously unlocked.
// See Unlock Chilkat Zip for sample code.
// First prepare a .zip and write it..
final zip = CkZip();
zip.newZip('qa_output/abc.zip');
// Add some files..
final charset = 'utf-8';
zip.addString('a.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', charset);
zip.addString('b.txt', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', charset);
zip.addString('c.txt', 'cccccccccccccccccccccccccccccccccccc', charset);
// Write to qa_output/abc.zip
// This .zip contains three files: a.txt, b.txt, and c.txt
zip.writeZipAndClose();
// -------------------------------------------------------------------
// Open abc.zip, replace the content of the "b.txt" entry with something else, and re-write.
final zip2 = CkZip();
zip2.openZip('qa_output/abc.zip');
final entry = CkZipEntry();
if (zip2.entryOf('b.txt', entry)) {
entry.replaceString('This is the new content. bbbbbbbbbbbbbbbbbbbbbb', 'utf-8');
}
// Write the modified .zip back to "abc.zip"
zip2.writeZipAndClose();
print('success.');
}