You can compress or decompress a Blob in OCL with SysSingleton.oclsingleton.Deflate when you need to transport compressed binary data, for example a SAML token in a URL.
Prerequisite
Set Eco.ExternalLateBound=true before calling this operation. The operation is accessed through SysSingleton.oclsingleton.
Operation
Deflate(bytes:Blob; inflate:Boolean):Blob
The bytes argument is the binary data to process. The inflate argument selects the direction:
| Value | Result |
|---|---|
false
|
Compress the input Blob. |
true
|
Decompress (inflate) the input Blob. |
The operation corresponds to the .NET DeflateStream functionality.
Compress text for URL transport
When your source is clear text, first convert it to a UTF-8 Base64 string and then to a Blob. Compress that Blob, convert the compressed result back to Base64, and URL-encode the Base64 value.
The following expression prepares XML for URL transport:
let compressedbase64=SysSingleton.oclsingleton.Deflate(xml.Replace('\r\n', ' ').Replace('\n', ' ').StringToBase64.Base64ToBlob,false).BlobToBase64 in
(
SysSingleton.oclsingleton.UrlEncode(compressedbase64,false)
)
In this example:
Replaceremoves line breaks fromxmlby replacing them with spaces.- StringToBase64 produces a Base64 representation of the text, and
Base64ToBlobcreates the Blob required byDeflate. Deflate(..., false)compresses the Blob.BlobToBase64makes the compressed binary result representable as text.- UrlEncode encodes that text so it can travel as a URL value.
Use the matching reverse sequence at the receiving end: URL-decode the value when applicable, convert the Base64 text to a Blob, call Deflate with true, and then convert the resulting Blob as required by the receiving code.
Decompress a Blob
Pass true as the second argument to inflate a previously compressed Blob. This example first decrypts a value, then inflates the decrypted Blob, and finally returns the result as Base64:
vAnswer:=SysSingleton.oclsingleton.Deflate(vCert.RSADecrypt( vAnswer.Base64ToBlob),true).blobtobase64
Here, vAnswer.Base64ToBlob converts the incoming Base64 value to binary data. The example assumes that vCert.RSADecrypt(...) returns the compressed Blob expected by Deflate. The final BlobToBase64 converts the inflated binary result to Base64.
Choose the correct conversion
Use the conversion that matches the data you have and the data the next operation expects:
| Situation | Conversion pattern |
|---|---|
You have clear text and need a Blob for Deflate
|
'My text'.StringToBase64.Base64ToBlob
|
| You have a compressed Blob and need text-safe representation | compressedBlob.BlobToBase64
|
| You will put Base64 text in a URL | Apply SysSingleton.oclsingleton.UrlEncode(base64Value,false).
|
For details on text and Base64 conversion, see Documentation:OCLOperators StringToBase64. If you need to explicitly convert between strings and byte arrays, see Documentation:Encoding.
