How to process binary-encoded data without writing to file and importing?

I am consuming a webservice through NETLink that returns data directly in the response as a gzipped csv file.

I can successfully process the data like this:

binz=response@data
BinaryWrite["tmp.csv.gz", binz]
Close["tmp.csv.gz"]
Import["tmp.csv.gz", "CSV"]


However, I am curious if there is a more direct way to achieve this? Thanks for any advice.

-

The following seems to work:

(* Simulate your response *)
binz = ExportString[ {"A System for Doing", "Mathematics by Computer"}, {"GZIP", "CSV"} ];

ImportString[binz, {"GZIP", "CSV"}]
(*
{{"A System for Doing"}, {"Mathematics by Computer"}}

*)


You may prefer to post a small data sample to test with your actual data format.

-

Base64 binary to text encoding may help, ie:

turtle = Import["ExampleData/turtle.jpg"];
gif = ExportString[turtle, "GIF"];
encoded = ExportString[gif, "Base64"];
ImportString[encoded, "Base64"]


However, Mathematica 7 requires this method:

turtle = Import["ExampleData/turtle.jpg"];
encoded = ExportString[turtle, {"Base64", "GIF"}];
ImportString[encoded, "Base64"]


For sending through NETLink you can use this:

kernel.Compute("ExportString[Graphics[Rectangle[]],{\"Base64\",\"EMF\"}]");
byte[] decodedBytes = Convert.FromBase64String(kernel.Result.ToString());
File.WriteAllBytes("C:\\Temp\\output.emf", decodedBytes);

-
+1. Did not know the form ExportString[expr, {"format", "format", ...}]. Where is it documented? It is equivalent to Fold[ExportString, expr, Reverse@{"format", "format", ...}]. For example, try: ExportString[Graphics[Rectangle[]], {"UUE", "Base64", "UUE", "EMF"}] === Fold[ExportString, Graphics[Rectangle[]], Reverse@{"UUE", "Base64", "UUE", "EMF"}]. – Alexey Popkov Jun 11 '12 at 8:48
As far as I know the ExportString/ImportString combo uses temporary files to work on. So, although you're not explicitely using files, you're still doing it under the hood. – Sjoerd C. de Vries Jun 11 '12 at 9:05
@ Alexey - I believe I found this syntax on the MathGroup. It doesn't seem to be eqivalent to Fold at least on Mma 7, since this does not work: encoded = Fold[ExportString, turtle, {"GIF", "Base64"}]; – Chris Degnen Jun 11 '12 at 9:59