Class AtomicWrite
Provides a temporary path to write to and atomically inserts it at the destination location on disposal (if Commit() was called).
Namespace: NanoByte.Common.Storage
Assembly: NanoByte.Common.dll
Syntax
public sealed class AtomicWrite : Object
Examples
using (var atomic = new AtomicWrite(filePath))
{
File.WriteAllBytes(atomic.WritePath, fileData);
atomic.Commit();
}
Constructors
AtomicWrite(String)
Prepares an atomic write operation.
Declaration
public AtomicWrite(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | The file path of the final destination. |
Properties
DestinationPath
The file path of the final destination.
Declaration
public string DestinationPath { get; }
Property Value
Type | Description |
---|---|
String |
IsCommitted
true
if Commit() has been called.
Declaration
public bool IsCommitted { get; }
Property Value
Type | Description |
---|---|
Boolean |
WritePath
The temporary file path to write to.
Declaration
public string WritePath { get; }
Property Value
Type | Description |
---|---|
String |
Methods
Commit()
Allows the new file to be deployed upon Dispose().
Declaration
public void Commit()
Dispose()
Replaces DestinationPath with the contents of WritePath.
Declaration
public void Dispose()