Add implementation of TBufferedFileStream
Original Reporter info from Mantis: JoshyFun @joshyfun
-
Reporter name: José Mejuto
Original Reporter info from Mantis: JoshyFun @joshyfun
- Reporter name: José Mejuto
Description:
Attached is an implementation of TBufferedFileStream.
I was not able to find a class definition from other pascal compiler so I assume that the public interface is the same as TFileStream.
This class is not a plain buffered stream, it is more like a cache as it can handle multiple blocks for read and write of arbitrary size, writen data is available for cache read, last used buffer page discard when cache space is needed...
There is a compatibility issue with direct replace with TFileStream, if a TFileStream is opened with fmOpenWrite (write only) this class requires to be changed to fmOpenReadWrite because the cache system needs to read data from file when a write to cache is performed as the write usually does not will overwrite the page completly and the class must synchronize the contents on disk with the memory contents. There is a solution that is add code in Create that if only fmOpenWrite is passed it will be transparently changed to fmOpenReadWrite but I decided to not take that route.
A bit optimizations can be added in both read and write when data to be read and write covers a complete cache page, but by now I decided to keep it more simple.
Additional information:
A test case is added in another source file, it will check that results of same operation in TFileStream and TBufferedStream returns same data and same positions.
Currently SetSize has not been tested.
Mantis conversion info:
- Mantis ID: 30549
- OS: Windows
- OS Build: Seven
- Build: N/A
- Platform: i386
- Version: 3.1.1
- Fixed in version: 3.3.1
- Fixed in revision: 42901 (#965f16a8)
- Target version: 3.2.0