diff --git a/casjobs.py b/casjobs.py
index <HASH>..<HASH> 100644
--- a/casjobs.py
+++ b/casjobs.py
@@ -264,6 +264,7 @@ class CasJobs(object):
 
         * `job_id` (int): The id of the _output_ job.
         * `outfn` (str): The file where the output should be stored.
+            May also be a file-like object with a 'write' method.
 
         """
         job_info = self.job_info(jobid=job_id)[0]
@@ -285,9 +286,12 @@ class CasJobs(object):
                     %(remotefn, code))
 
         # Save the data to a file.
-        f = open(outfn, "wb")
-        f.write(r.content)
-        f.close()
+        try:
+            outfn.write(r.content)
+        except AttributeError:
+            f = open(outfn, "wb")
+            f.write(r.content)
+            f.close()
 
     def request_and_get_output(self, table, outtype, outfn):
         """
@@ -303,6 +307,7 @@ class CasJobs(object):
             FITS    - Flexible Image Transfer System (FITS Binary)
             VOTable - XML Virtual Observatory VOTABLE
         * `outfn` (str): The file where the output should be stored.
+            May also be a file-like object with a 'write' method.
 
         """
         job_id = self.request_output(table, outtype)
allow file-like object as parameter to get_output

If the outfn parameter to get_output has a write() method, that is used
for the output rather than opening a new file.  This allows e.g. a
StringIO object to be passed in so that output can be captured in
memory rather than creating a temporary file.