Sample code for 30+ languages & platforms
Node.js

Compress Bytes

See more Compression Examples

Demonstrates how to compress binary data.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    //  This example assumes the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    var fac = new chilkat.FileAccess();

    fileBytes = fac.ReadEntireFile("qa_data/bmp/big.bmp");
    if (fac.LastMethodSuccess !== true) {
        console.log(fac.LastErrorText);
        return;
    }

    var compress = new chilkat.Compression();
    compress.Algorithm = "deflate";

    compressedBytes = compress.CompressBytes(fileBytes);
    if (compress.LastMethodSuccess !== true) {
        console.log(compress.LastErrorText);
        return;
    }

    success = fac.WriteEntireFile("qa_output/compressedBmp.dat",compressedBytes);
    if (fac.LastMethodSuccess !== true) {
        console.log(fac.LastErrorText);
        return;
    }


}

chilkatExample();