I receive some data as a string.  I need to write the data to a file, but the problem is that sometimes the data is compressed/zipped and sometimes it's just plain text.  I need to determine the content-type so I know whether to write it to a .txt file or a .tgz file.  Any ideas on how to accomplish this?  Can I use mime type somehow even though my data is a string, not a file?
Thanks.
If the file is downloaded from a webserver, you should have a content-type to look at, however you are at the mercy of the webserver whether or not it truly describes the type of the file.
Another alternative would be to use a heuristic to guess the file type. This can often be done by looking at the first few bytes of the file
How to determine content type of a string