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.
Both gzip and zip use distinct headers before compressed data, rather unlikely for human-readable strings. If the choice is only between these, you can make a faster check than mimetypes would provide.
How to determine content type of a string