Dart Requires Chilkat v11.0.0+
Dart
Decompress Large Binary File in Blocks
See more Compression Examples
Decompresses a large binary file in blocks.Chilkat Dart Downloads
import 'dart:typed_data';
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 facSrc = CkFileAccess();
final facDest = CkFileAccess();
// Open a previously compressed file for decompressing.
// See Compress Large File in Blocks
try {
facSrc.openForRead('c:/temp/qa_output/compressedBmp.dat');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// If we compress in 32K chunks, find out how many blocks there will be.
final blockSize = 32768;
final numBlocks = facSrc.getNumBlocks(blockSize);
// Open an output file for the decompressed data.
try {
facDest.openForWrite('c:/temp/qa_output/decompressed.bmp');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final compress = CkCompression();
compress.algorithm = 'deflate';
var decompressedBytes = Uint8List(0);
var compressedBytes = Uint8List(0);
// Assuming numBlocks > 1
compress.firstChunk = true;
compress.lastChunk = false;
var i = 0;
while (i < numBlocks) {
compressedBytes = facSrc.readBlock(i, blockSize);
decompressedBytes = compress.decompressBytes(compressedBytes);
facDest.fileWrite(decompressedBytes);
i++;
compress.firstChunk = false;
if (i == (numBlocks - 1)) {
compress.lastChunk = true;
}
}
facSrc.fileClose();
facDest.fileClose();
print('Finished decompressing file.');
}