![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(Node.js) Replacment for Deprecated Crypt2 Compress FunctionsThe Chilkat Crypt2 compression functions are deprecated and will be removed. This example shows how to duplicate the functionality using the Chilkat Compression class.
var os = require('os'); if (os.platform() == 'win32') { var chilkat = require('@chilkat/ck-node23-win64'); } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node23-linux-arm'); } else if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node23-linux-arm64'); } else { var chilkat = require('@chilkat/ck-node23-linux-x64'); } } else if (os.platform() == 'darwin') { var chilkat = require('@chilkat/ck-node23-mac-universal'); } function chilkatExample() { var crypt = new chilkat.Crypt2(); // Create data to be compressed. var sb = new chilkat.StringBuilder(); var i = 0; while (i < 25) { sb.Append("Hello World, this is a test.\r\n"); i = i+1; } // Bzip2 compress the utf-8 byte representation of the string and return the compressed data as base64. crypt.Charset = "utf-8"; crypt.EncodingMode = "base64"; var compressedStr = crypt.CompressStringENC(sb.GetAsString()); console.log(compressedStr); // Result: 4aeUs+4CAABCWmgzMUFZJlNZZ6znBgAAfNeAABJABQBAAIAmZJwAIABwUNNMAAUqoekYjMp4ixF1FlFxF8i5i1FvFwizF9iwi9RdxaizF7RZi6i0ixF3Fui/i7kinChIM9ZzgwA= // The result contains an 8-byte header composed of a 4-byte magic number (0xB394A7E1) and a 4-byte length. // Do the following to BZip2 decompress using Chilkat Compression var bd = new chilkat.BinData(); bd.AppendEncoded(compressedStr,"base64"); // Remove the 8-byte header. bd.RemoveChunk(0,8); // Decompress var compress = new chilkat.Compression(); compress.Algorithm = "bzip2"; compress.DecompressBd(bd); // Get the decompressed string. var decompressedStr = bd.GetString("utf-8"); console.log(decompressedStr); } chilkatExample(); |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.