gunzip without a file

Hi all, my web page parsing program stopped working today because they started gzipping their content. I use the PageReceived event and my fix for now is to write it out to a file, gunzip and read back in; but I’d rather not have to go out through a file. Is that possible? The man pages say it’ll process standard input to standard output but I don’t know how to use those, and maybe I’m misreading :slight_smile: (for mac if that makes a difference)

This is the current file round-tripping. If I have to use this is it sound?

[code]Sub PageReceived(…, content as string)

//content is gzipped
dim f As FolderItem = SpecialFolder.Temporary.Child(“agcontent.gz”)
dim bs As BinaryStream = BinaryStream.Create(f, true)
bs.Write(content)
bs.close
bs = nil

dim sh As new Shell
sh.Execute("gunzip " + f.ShellPath)
sh = nil

f = SpecialFolder.Temporary.Child(“agcontent”)
bs = BinaryStream.Open(f)
content = bs.Read(bs.Length, Encodings.UTF8)
bs.close
bs = nil
f.Delete
f = nil

//content now html, parse as before
//…

End Sub[/code]

Thomas Templeman has cream, I mean code for this.

Xojo actually has built in gzip, gunzip methods that work on memory or files. They are private and have changed over the course of time. Seems a shame to have the functionality already in the standard library but not be able to use it.

<https://xojo.com/issue/20404>

In the mean time, I found somewhere, should have recorded, a gzip library. It’s declares around the gzip library. If you’re interested, I’ll put it up somewhere for you to grab.

Thanks guys. What a rabbit hole. I don’t really much at all understand how gzip, zlib, command line and declaring all work together. From a snippet posted by Eli Ott a couple weeks ago I think the declare lib would be “libz.dylib”. There’s actually 4 libz.*.dylib files in my ~usr/lib/ folder. Then it would be translating this code which I very tentatively think maybe I follow. Looks like a lot of work.

In terminal I was able to get gzip compressing standard input to a file
$ gzip > test.gz [return]
apples [return][control-d]
$

and then decompress the file to standard output
$ gzip -c -d test.gz [return]
apples
$

Doing them together seems to be prohibited: “If no files are specified, gzip will compress from standard input, OR decompress to standard output.”

So now I look for Thomas Tempelmanns code… voila. ZLibInflator.Inflate look like the lot-of-work :slight_smile: Will work it tomorrow, very tired. I use Thomas’ global hotkey code too, need to keep these links handier.

I have been using MBS Compression plug-in and the in-memory decompression for many years and it has saved me hours and hours of work. It works with zip and gz.

We have UnzipMBS and GZipFileMBS classes in MBS Plugin and they work in memory only if you like.

[quote=85516:@Jeremy Cowgar]Xojo actually has built in gzip, gunzip methods that work on memory or files. They are private and have changed over the course of time. Seems a shame to have the functionality already in the standard library but not be able to use it.

<https://xojo.com/issue/20404>

In the mean time, I found somewhere, should have recorded, a gzip library. It’s declares around the gzip library. If you’re interested, I’ll put it up somewhere for you to grab.[/quote]

in Feedback 19807 you find an example how to use the internal RS lib. but Xojo advise not to use it.

Xojo/RS recommend not to use this code below

[code]
//---------
// Example how to use Xojo’s internal Gzip
//Compress String with _GzipString:
//---------
Dim s As String = “Uncompressed String”
Dim s1 As String

Dim GzipString As new _GzipString

//Compressed String
s1 = GzipString.Compress(s)
---------[/code]

[quote=85576:@John Hansen]in Feedback 19807 you find an example how to use the internal RS lib. but Xojo advise not to use it.

Xojo/RS recommend not to use this code below [/quote]

Right, because they have not declared the API stable. That is what <https://xojo.com/issue/20404> is for. It asks Xojo to solidify the API and make it public. Then it would be recommended.