https://github.com/lawrence-laz/transactional-io
Manipulate FileStreams in a transactional manner.
https://github.com/lawrence-laz/transactional-io
csharp dotnet filestream nuget resilience transaction
Last synced: 4 months ago
JSON representation
Manipulate FileStreams in a transactional manner.
- Host: GitHub
- URL: https://github.com/lawrence-laz/transactional-io
- Owner: lawrence-laz
- License: mit
- Created: 2023-01-18T20:35:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-18T08:55:35.000Z (over 2 years ago)
- Last Synced: 2025-02-25T10:50:36.918Z (4 months ago)
- Topics: csharp, dotnet, filestream, nuget, resilience, transaction
- Language: C#
- Homepage:
- Size: 776 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/Transactional.IO/)
[](https://www.nuget.org/packages/Transactional.IO/)
[](https://github.com/lawrence-laz/transactional-io/actions?query=workflow%3ABuild)
[](https://www.codacy.com/gh/lawrence-laz/transactional-io/dashboard?utm_source=github.com&utm_medium=referral&utm_content=lawrence-laz/transactional-io&utm_campaign=Badge_Grade)
[](https://www.codacy.com/gh/lawrence-laz/transactional-io/dashboard?utm_source=github.com&utm_medium=referral&utm_content=lawrence-laz/transactional-io&utm_campaign=Badge_Coverage)# 📁 Transactional.IO
A dead simple way to manage your `FileStream` in a transactional way to ensure
that the file does not get corrupted if things don't go as planned.Take an example with `XmlWriter` (note that any `StreamWriter` is compatible, including the direct access!)
```csharp
using Transactional.IO;
using System.Xml;using var stream = new TransactionalFileStream("my-file.xml", FileMode.Truncate);
using var writer = XmlWriter.Create(stream);var userFullName = "";
writer.WriteStartDocument();
writer.WriteStartElement("User");
if (userFullName == "")
{
// ❌ This interrupts execution and writer does not finish.
// Your file would be left corrupted with half of XML missing.
throw new Exception("Uh-oh!");
}
writer.WriteValue(userFullName);
writer.WriteEndElement();writer.WriteEndDocument();
// ✅ But don't fret!
// As long as .Commit() was not called, the original file is left unchanged.
stream.Commit();
```## 🌟 Features
- As simple as it gets, no bloated custom APIs
- Extends standard `System.IO.FileStream`## 📦️ Get started
Download from [nuget.org](https://www.nuget.org/packages/Transactional.IO/):
```powershell
dotnet add package Transactional.IO
```