Changeset 11435 for trunk/Mars/mbase
- Timestamp:
- 07/18/11 13:20:42 (13 years ago)
- Location:
- trunk/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mbase/MZlib.cc
r11434 r11435 111 111 // -------------------------------------------------------------------------- 112 112 // 113 #include <iostream> 113 114 # if (__GNUC__>2) 114 115 streambuf::pos_type MZlib::seekoff(streambuf::off_type offset, ios_base::seekdir dir, … … 125 126 // warning: case value `2' not in enumerated type `_Ios_Seekdir' 126 127 127 if (dir==ios:: cur)128 if (dir==ios::end) 128 129 { 129 // Calculate future position in streambuffer 130 const char *ptr = gptr()+offset; 130 clear(rdstate()|ios::failbit); 131 return EOF; 132 } 131 133 132 // Position in z-stream 133 const z_off_t zpos = gztell(fFile)+gptr()-egptr(); //gzseek(fFile, 0, SEEK_CUR); 134 // We only do relative seeking to avoid unnecessary decompression 135 // of the whole file 136 if (dir==ios::beg) 137 offset -= tellg(); 134 138 135 // Check if the new position will still be in the buffer 136 // In this case the target data was already decompressed. 137 if (ptr<eback() || ptr>=egptr()) 138 return seekpos(zpos+ptr-egptr()); 139 // Calculate future position in streambuffer 140 const char *ptr = gptr()+offset; 141 142 // This is the number of bytes still available in the buffer 143 const size_t sbuf = egptr()-gptr(); 144 145 // Check if the new position will still be in the buffer 146 // In this case the target data was already decompressed. 147 if (ptr>=eback() && ptr<egptr()) 148 { 149 // Absolute position in z-stream 150 const z_off_t zpos = gztell(fFile)-sbuf; //gzseek(fFile, 0, SEEK_CUR); 139 151 140 152 gbump(offset); 153 141 154 return zpos+offset; 142 143 // zpos-blen: Position in z-stream coresponding to buffer position144 // return seekpos(gztell(fFile)+gptr()-egptr()+offset);145 155 } 146 156 147 if (dir==ios::beg) 148 return seekpos(offset); 157 const streampos pos = gzseek(fFile, offset-sbuf, SEEK_CUR); 158 159 // Buffer is empty - force refilling 160 setg(fBuffer+4, fBuffer+4, fBuffer+4); 161 162 return pos<0 ? streampos(EOF) : pos; 149 163 150 164 /* … … 172 186 # endif 173 187 { 174 // Seek the z-stream to the given position 175 if (gzseek(fFile, pos, SEEK_SET)<0) 176 return EOF; 177 178 // Buffer is empty 179 setg(fBuffer+4, fBuffer+4, fBuffer+4); 180 181 return pos; 188 return seekoff(pos, ios::beg); 182 189 } -
trunk/Mars/mbase/MZlib.h
r11434 r11435 48 48 # else 49 49 std::streampos seekoff(std::streamoff, int, int = std::ios::in); 50 std::streampos seekpos(std::streampos, int = std::ios::in);50 // std::streampos seekpos(std::streampos, int = std::ios::in); 51 51 # endif 52 52
Note:
See TracChangeset
for help on using the changeset viewer.