Android Question .gz and .xz extracter

Scantech

Well-Known Member
Licensed User
Longtime User
Do we have extractor for .xz and .gz files? I searched and negative result.
 

JackKirk

Well-Known Member
Licensed User
Longtime User
I came across this thread after I managed to solve the same problem without a library (well not a .gz specific one any rate):
B4X:
            'Following courtesy of Windows Copilot
            'Unzip .gz file to string Gen_log_file_records
            Private wrk_jo As JavaObject
            wrk_jo = wrk_jo.InitializeNewInstance("java.util.zip.GZIPInputStream", Array(wrk_AWS_S3_B4J.Payload_inputstream))
            Private wrk_out As OutputStream
            wrk_out.InitializeToBytesArray(0)
            File.Copy2(wrk_jo, wrk_out)
            Private wrk_bc As ByteConverter
            Gen_log_file_records = wrk_bc.StringFromBytes(wrk_out.ToBytesArray, "UTF-8")

wrk_AWS_S3_B4J.Payload_inputstream is an input stream - in my case via a http job to read an AWS Cloudfront log file (which are always supplied as .gz) from an AWS S3 bucket.

Gen_log_file_records is the extracted records in string form, each record separated by a CRLF (Chr(10)).

As noted in my comments I got this by asking Windows Copilot - took 2 or 3 iterations but it knows B4J to some extent - although initially it did dream up a method that does not exist. When I pointed this out it thanked me and came up with the above.

I continue to be impressed with it.
 
Last edited:
Upvote 0
Top