Dart Requires Chilkat v11.0.0+
Dart
Compress String Feed to Base64
See more Compression Examples
This example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed data in base64.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final sbCompressedBase64 = CkStringBuilder();
final compress = CkCompression();
compress.algorithm = 'deflate';
compress.charset = 'utf-8';
compress.encodingMode = 'base64';
compress.firstChunk = true;
compress.lastChunk = false;
final bdCompressed = CkBinData();
final sbUncompressedChunk = CkStringBuilder();
for (var i = 0; i <= 24; i++) {
if (i == 24) {
compress.lastChunk = true;
}
sbUncompressedChunk.clear();
sbUncompressedChunk.appendInt(i);
sbUncompressedChunk.append(': This is a line of data to be compressed...\r\n');
compress.compressSb(sbUncompressedChunk, bdCompressed);
compress.firstChunk = false;
}
print('The base64 encoded compressed text:');
print(bdCompressed.getEncoded('base64'));
// Decompress in one call:
final originalText = compress.decompressStringENC(bdCompressed.getEncoded('base64'));
print(originalText);
}