]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
zlib stuff
[lyx.git] / src / buffer.C
index b7afa7c11a69504c38f2178cd4b89e22159cfea6..d242264a1f2a8156b4613febfdeee4c22dde0df5 100644 (file)
@@ -65,6 +65,7 @@
 #include "support/FileInfo.h"
 #include "support/lyxmanip.h"
 #include "support/lyxtime.h"
+#include "support/gzstream.h"
 
 #include <boost/bind.hpp>
 #include <boost/tuple/tuple.hpp>
@@ -115,7 +116,7 @@ extern BufferList bufferlist;
 
 namespace {
 
-const int LYX_FORMAT = 224;
+const int LYX_FORMAT = 225;
 
 bool openFileWrite(ofstream & ofs, string const & fname)
 {
@@ -636,10 +637,29 @@ bool Buffer::writeFile(string const & fname) const
                return false;
        }
 
+       bool const compressed = (fname.substr(fname.size() - 3, 3) == ".gz");
+
+       if (compressed) {
+               gz::ogzstream ofs(fname.c_str());
+
+               if (!ofs)
+                       return false;
+
+               return do_writeFile(ofs);
+
+       }
+
        ofstream ofs(fname.c_str());
        if (!ofs)
                return false;
 
+       return do_writeFile(ofs);
+}
+
+
+bool Buffer::do_writeFile(ostream & ofs) const
+{
+
 #ifdef HAVE_LOCALE
        // Use the standard "C" locale for file output.
        ofs.imbue(std::locale::classic());
@@ -669,7 +689,8 @@ bool Buffer::writeFile(string const & fname) const
        // Write marker that shows file is complete
        ofs << "\n\\the_end" << endl;
 
-       ofs.close();
+       // Shouldn't really be needed....
+       //ofs.close();
 
        // how to check if close went ok?
        // Following is an attempt... (BE 20001011)