diff --git a/poppler/Stream.cc b/poppler/Stream.cc index 6ffd5d3..b2f2e2d 100644 --- a/poppler/Stream.cc +++ b/poppler/Stream.cc @@ -750,21 +750,6 @@ GBool StreamPredictor::getNextLine() { } //------------------------------------------------------------------------ -// UniqueFileStream -//------------------------------------------------------------------------ - -UniqueFileStream::UniqueFileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA, - Goffset lengthA, Object *dictA): - FileStream(fA, fileNameA, startA, limitedA, lengthA, dictA) { - f = fopen(fileName, "rb"); -} - -UniqueFileStream::~UniqueFileStream() { - close(); - fclose(f); -} - -//------------------------------------------------------------------------ // FileStream //------------------------------------------------------------------------ @@ -780,6 +765,9 @@ FileStream::FileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA bufPos = start; savePos = 0; saved = gFalse; + + fd = fileno(f); + offset = start; } FileStream::~FileStream() { @@ -787,7 +775,7 @@ FileStream::~FileStream() { } BaseStream *FileStream::copy() { - return new UniqueFileStream(f, fileName, start, limited, length, &dict); + return new FileStream(f, fileName, start, limited, length, &dict); } Stream *FileStream::makeSubStream(Goffset startA, GBool limitedA, @@ -796,16 +784,23 @@ Stream *FileStream::makeSubStream(Goffset startA, GBool limitedA, } void FileStream::reset() { - savePos = Gftell(f); + /*savePos = Gftell(f); Gfseek(f, start, SEEK_SET); saved = gTrue; bufPtr = bufEnd = buf; + bufPos = start;*/ + savePos = offset; + offset = start; + saved = gTrue; + bufPtr = bufEnd = buf; bufPos = start; } void FileStream::close() { if (saved) { - Gfseek(f, savePos, SEEK_SET); + /*Gfseek(f, savePos, SEEK_SET); + saved = gFalse;*/ + offset = savePos; saved = gFalse; } } @@ -823,7 +818,9 @@ GBool FileStream::fillBuf() { } else { n = fileStreamBufSize; } - n = fread(buf, 1, n, f); + //n = fread(buf, 1, n, f); + n = pread(fd, buf, n, offset); + offset += n; bufEnd = buf + n; if (bufPtr >= bufEnd) { return gFalse; @@ -835,15 +832,18 @@ void FileStream::setPos(Goffset pos, int dir) { Goffset size; if (dir >= 0) { - Gfseek(f, pos, SEEK_SET); + //Gfseek(f, pos, SEEK_SET); + offset = pos; bufPos = pos; } else { Gfseek(f, 0, SEEK_END); size = Gftell(f); if (pos > size) pos = size; - Gfseek(f, -pos, SEEK_END); - bufPos = Gftell(f); + /*Gfseek(f, -pos, SEEK_END); + bufPos = Gftell(f);*/ + offset = size - pos; + bufPos = offset; } bufPtr = bufEnd = buf; } diff --git a/poppler/Stream.h b/poppler/Stream.h index dfcd530..451b49a 100644 --- a/poppler/Stream.h +++ b/poppler/Stream.h @@ -503,14 +503,9 @@ private: Goffset bufPos; Goffset savePos; GBool saved; -}; - -class UniqueFileStream: public FileStream { -public: - - UniqueFileStream(FILE *fA, char *fileNameA, Goffset startA, GBool limitedA, - Goffset lengthA, Object *dictA); - virtual ~UniqueFileStream(); + + int fd; + Goffset offset; }; //------------------------------------------------------------------------