Index: trunk/Mars/mbase/MZlib.cc
===================================================================
--- trunk/Mars/mbase/MZlib.cc	(revision 11434)
+++ trunk/Mars/mbase/MZlib.cc	(revision 11435)
@@ -111,4 +111,5 @@
 // --------------------------------------------------------------------------
 //
+#include <iostream>
 # if (__GNUC__>2)
 streambuf::pos_type MZlib::seekoff(streambuf::off_type offset, ios_base::seekdir dir,
@@ -125,26 +126,39 @@
     //  warning: case value `2' not in enumerated type `_Ios_Seekdir'
 
-    if (dir==ios::cur)
+    if (dir==ios::end)
     {
-        // Calculate future position in streambuffer
-        const char *ptr = gptr()+offset;
+        clear(rdstate()|ios::failbit);
+        return EOF;
+    }
 
-        // Position in z-stream
-        const z_off_t zpos = gztell(fFile)+gptr()-egptr(); //gzseek(fFile, 0, SEEK_CUR);
+    // We only do relative seeking to avoid unnecessary decompression
+    // of the whole file
+    if (dir==ios::beg)
+        offset -= tellg();
 
-        // Check if the new position will still be in the buffer
-        // In this case the target data was already decompressed.
-        if (ptr<eback() || ptr>=egptr())
-            return seekpos(zpos+ptr-egptr());
+    // Calculate future position in streambuffer
+    const char *ptr = gptr()+offset;
+
+    // This is the number of bytes still available in the buffer
+    const size_t sbuf = egptr()-gptr();
+
+    // Check if the new position will still be in the buffer
+    // In this case the target data was already decompressed.
+    if (ptr>=eback() && ptr<egptr())
+    {
+        // Absolute position in z-stream
+        const z_off_t zpos = gztell(fFile)-sbuf; //gzseek(fFile, 0, SEEK_CUR);
 
         gbump(offset);
+
         return zpos+offset;
-
-        // zpos-blen: Position in z-stream coresponding to buffer position
-        // return seekpos(gztell(fFile)+gptr()-egptr()+offset);
     }
 
-    if (dir==ios::beg)
-        return seekpos(offset);
+    const streampos pos = gzseek(fFile, offset-sbuf, SEEK_CUR);
+
+    // Buffer is empty - force refilling
+    setg(fBuffer+4, fBuffer+4, fBuffer+4);
+
+    return pos<0 ? streampos(EOF) : pos;
 
     /*
@@ -172,11 +186,4 @@
 # endif
 {
-    // Seek the z-stream to the given position
-    if (gzseek(fFile, pos, SEEK_SET)<0)
-        return EOF;
-
-    // Buffer is empty
-    setg(fBuffer+4, fBuffer+4, fBuffer+4);
-
-    return pos;
+    return seekoff(pos, ios::beg);
 }
Index: trunk/Mars/mbase/MZlib.h
===================================================================
--- trunk/Mars/mbase/MZlib.h	(revision 11434)
+++ trunk/Mars/mbase/MZlib.h	(revision 11435)
@@ -48,5 +48,5 @@
 # else
     std::streampos seekoff(std::streamoff, int, int = std::ios::in);
-    std::streampos seekpos(std::streampos, int = std::ios::in);
+//    std::streampos seekpos(std::streampos, int = std::ios::in);
 # endif
 
