React Native
React Native
Compress Bytes
See more Compression Examples
Demonstrates how to compress binary data.Chilkat React Native Downloads
import { Compression, FileAccess } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const fac = new FileAccess();
const fileBytes = fac.readEntireFile('qa_data/bmp/big.bmp');
if (!fac.lastMethodSuccess) {
console.log(fac.lastErrorText);
return;
}
const compress = new Compression();
compress.algorithm = 'deflate';
const compressedBytes = await compress.compressBytesAsync(fileBytes);
if (!compress.lastMethodSuccess) {
console.log(compress.lastErrorText);
return;
}
try {
fac.writeEntireFile('qa_output/compressedBmp.dat', compressedBytes);
} catch {
console.log(fac.lastErrorText);
return;
}
}