Question
Rodolfo Santos · Jun 12, 2019

How to open file inside temporary GZIP archive?

Hello Everyone

I'm trying to open an XML that I get inside a GZIP file.
However, I can only open the contents when I save the file to a folder.
I would like to know if there is a way to get the contents of XML without saving the GZIP in a folder.

The code below is functional, however, you are saving GZIP before you can get the contents of the XML.

SET tGZIP = $System.Encryption.Base64Decode("############")
SET tFile= ##class(%File).%New("####")
SET tSC = tFile.Open("WSN")
SET tSC = tFile.Write(tGZIP)
DO tFile.%Save()
DO tFile.Close()
SET tSC = tFile.Open("RUK:::/GZIP=1:/NOXY=1")
WHILE 'tFile.AtEnd
 {
   SET tXML = tFile.ReadLine()
 }

 

00
0 2 173 1

Replies

Hi Rodolfo,

If I understand correctly your question, using Base64Decode, you will get it:

set tGZIP=$System.Encryption.Base64Encode("This is my original XML")
write !,tGZIP

set tXML=$System.Encryption.Base64Decode(tGZIP)

write !,tXML
quit

Running this you get:

USER>d ^gzip
 
VGhpcyBpcyBteSBvcmlnaW5hbCBYTUw=
This is my original XML

$SYSTEM.Util.Decompress() and $SYSTEM.Util.Compress() can help you to decompress and compress any data from/to gzip just from string