Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

BinaryWrite["tmp.csv.gz", binz]
Import["tmp.csv.gz", "CSV"]

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

share|improve this question

The following seems to work:

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

(*Uncompress and read 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.

share|improve this answer

Base64 binary to text encoding may help, ie:

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

enter image description here

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:

byte[] decodedBytes = Convert.FromBase64String(kernel.Result.ToString());
File.WriteAllBytes("C:\\Temp\\output.emf", decodedBytes);
share|improve this answer
+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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.