@@ -571,7 +571,7 @@ class CAutoFile : public AutoFile
571571 }
572572};
573573
574- /* * Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to
574+ /* * Wrapper around a CAutoFile& that implements a ring buffer to
575575 * deserialize from. It guarantees the ability to rewind a given number of bytes.
576576 *
577577 * Will automatically close the file when it goes out of scope if not null.
@@ -580,9 +580,7 @@ class CAutoFile : public AutoFile
580580class BufferedFile
581581{
582582private:
583- const int nVersion;
584-
585- FILE *src; // !< source file
583+ CAutoFile& m_src;
586584 uint64_t nSrcPos{0 }; // !< how many bytes have been read from source
587585 uint64_t m_read_pos{0 }; // !< how many bytes have been read from this
588586 uint64_t nReadLimit; // !< up to which position we're allowed to read
@@ -598,9 +596,9 @@ class BufferedFile
598596 readNow = nAvail;
599597 if (readNow == 0 )
600598 return false ;
601- size_t nBytes = fread (( void *)& vchBuf[ pos], 1 , readNow, src) ;
599+ size_t nBytes{m_src. detail_fread (Span{ vchBuf}. subspan ( pos, readNow))} ;
602600 if (nBytes == 0 ) {
603- throw std::ios_base::failure ( feof (src ) ? " BufferedFile::Fill: end of file" : " BufferedFile::Fill: fread failed" ) ;
601+ throw std::ios_base::failure{m_src. feof () ? " BufferedFile::Fill: end of file" : " BufferedFile::Fill: fread failed" } ;
604602 }
605603 nSrcPos += nBytes;
606604 return true ;
@@ -629,19 +627,18 @@ class BufferedFile
629627 }
630628
631629public:
632- BufferedFile (FILE* fileIn , uint64_t nBufSize, uint64_t nRewindIn, int nVersionIn )
633- : nVersion{nVersionIn }, nReadLimit{std::numeric_limits<uint64_t >::max ()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0 })
630+ BufferedFile (CAutoFile& file , uint64_t nBufSize, uint64_t nRewindIn)
631+ : m_src{file }, nReadLimit{std::numeric_limits<uint64_t >::max ()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0 })
634632 {
635633 if (nRewindIn >= nBufSize)
636634 throw std::ios_base::failure (" Rewind limit must be less than buffer size" );
637- src = fileIn;
638635 }
639636
640- int GetVersion () const { return nVersion ; }
637+ int GetVersion () const { return m_src. GetVersion () ; }
641638
642639 // ! check whether we're at the end of the source file
643640 bool eof () const {
644- return m_read_pos == nSrcPos && feof (src );
641+ return m_read_pos == nSrcPos && m_src. feof ();
645642 }
646643
647644 // ! read a number of bytes
0 commit comments