function rti_compress_string(inString, status) *#!Precompile /* * This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without * written permission from Revelation Technologies, Inc. ! * No warranties, express or implied, are conveyed by the use of this routine ! * VERSION : 1.0 * * * AUTHOR : Bryan Shumsky * * CREATED : February 16, 2022 * * ! * * REVISION HISTORY (Most CURRENT first) : * * DATE IMPLEMENTOR FUNCTION * -------- ----------- -------- * */ $Insert RevDotNetEquates If Assigned(inString) Else inString = "" Status = 0 rslt = "" If inString = "" Then Status = "-2" Return rslt End dotNetHandle = "" dotNetVersion = "4.0" oNet = StartDotNet("", dotNetVersion, dotNetHandle) if Get_Status(errcode) Then Goto returnErr End netLocn = CheckDotNet(dotNetVersion) If netLocn <> "0" And netLocn <> "" Then If netLocn[-1,1] <> "\" Then netLocn := "\" End Else netLocn = "" oiLocn = drive() If oiLocn[-1,1] <> "\" Then oiLocn := "\" x = set_property.net(oNet, "AssemblyName", netLocn:"System.dll":@fm:netLocn:"mscorlib.dll", dotNetHandle) If Get_Status(errcode) Then Goto returnErr * step 1: convert incoming string into an array of UTF8 bytes, and make a "memory stream" from that byte array oEncoding = create_class.net(oNet, "System.Text.UTF8Encoding", 0, "", "", dotNetHandle) If Get_Status(errcode) Then Goto returnErr oBytes = send_message.net(oEncoding, "GetBytes", inString, "System.String", 1, dotNetHandle) If Get_Status(errcode) Then Goto returnErr oInputStream = create_class.net(oNet, "System.IO.MemoryStream", 0, oBytes, "", dotNetHandle) If Get_Status(errcode) Then Goto returnErr * step 2: use gzipstream to compress the incoming memory stream to an outgoing memory stream oOutputStream = create_class.net(oNet, "System.IO.MemoryStream", 0, "", "", dotNetHandle) If Get_Status(errcode) Then Goto returnErr oCompressor = create_class.net(oNet, "System.IO.Compression.GZipStream", 0, oOutputStream:@FM:"1":@FM:"True", "":@FM:"System.IO.Compression.CompressionMode":@FM:"System.Boolean", dotNetHandle) If Get_Status(errcode) Then Goto returnErr dummy = send_message.net(oInputStream, "CopyTo", oCompressor, "", 0, dotNetHandle) If Get_Status(errcode) Then Goto returnErr * note: must close the gzipstream to "flush" the contents dummy = send_message.net(oCompressor, "Close", "", "", 0, dotNetHandle) If Get_Status(errcode) Then Goto returnErr * step 3: turn the outgoing memory stream into an array of bytes oCompressed = send_message.net(oOutputStream, "ToArray", "", "", 1, dotNetHandle) If Get_Status(errcode) Then Goto returnErr * note: must close the streams dummy = send_message.net(oOutputStream, "Close", "", "", 0, dotNetHandle) dummy = send_message.net(oInputStream, "Close", "", "", 0, dotNetHandle) * step 4: convert the compressed array of bytes into a base64 encoded string oConverter = create_class.net(oNet, "System.Convert", 0, "", "", dotNetHandle) If Get_Status(errcode) Then Goto returnErr rslt = send_message.net(oConverter, "ToBase64String", oCompressed, "", 0, dotNetHandle) If Get_Status(errcode) Then Goto returnErr Goto wrapup returnErr: * error handling here * Do something With errcode Status = "-1" wrapup: free_class.net("", dotNetHandle) Return rslt