File Revision Store
FileRevisionStore
class handles file revision storage. It caters for concurrent safe read/write operations across the entire application using a globally unique thread-safe lock. This class also offers the following features:
File verification processing
Data file versioning with a system-level transactional replace to prevent partial file writes or data corruption
Ability to rewind corrupt files back to a previous version when verification fails
An
UpdateFile
method that performs a thread-locked read/write on the same transaction
The "revision checked" feature serves as a safety mechanism in the FileRevisionStore
, ensuring the integrity of the files written to disk. Before overwriting, each file is assigned a revision, and the bytes are transactionally verified to prevent partial or corrupt file writes. This meticulous verification process safeguards the data by confirming that only complete and accurate revisions are written, thus minimizing the risk of data corruption or loss due to incomplete or erroneous file writes.
SaveFile
This method saves a file and returns a boolean value indicating if the operation was successful.
The Path is supplied to where the file is stored.
A byte array is passed of the data to store
A Verification function is optionally supplied to verify the data written to disk.
In the example below, we're writing data using JsonCompress. The verification function is simply checking that we can decompress the bytes again from disk.
Example:
ReadFile Method
ReadFile
method reads a file and performs verification.
The Path is supplied to where the file is stored.
An out boolean is sent back saying whether or not the validation was a failure.
A Verification function is optionally supplied to verify the data read back from the disk.
In the below example, we are using JsonCompress to verify the data can be decompressed from disk without an exception thrown.
Example:
UpdateFile Method
UpdateFile
method performs a thread-locked read/write operation on the same transaction.
It's very similar to the above two methods:
The Path is supplied to where the file is stored.
An out boolean is sent back saying whether or not the validation was a failure.
A callback with the bytes being read is supplied, this is how you update the file
A Verification function is optionally supplied to verify the data read back from the disk.
This is actually called twice in the update cycle. Once on file read, and a second time on file write.
Example:
Last updated