Table of Contents

Class AtomicWrite

Namespace
NanoByte.Common.Storage
Assembly
NanoByte.Common.dll

Provides a temporary path to write to and atomically inserts it at the destination location on disposal (if Commit() was called).

[MustDisposeResource]
public sealed class AtomicWrite
Inheritance
AtomicWrite
Extension Methods

Examples

using (var atomic = new AtomicWrite(filePath))
{
    File.WriteAllBytes(atomic.WritePath, fileData);
    atomic.Commit();
}

Constructors

AtomicWrite(string)

Prepares an atomic write operation.

public AtomicWrite(string path)

Parameters

path string

The file path of the final destination.

Properties

DestinationPath

The file path of the final destination.

public string DestinationPath { get; }

Property Value

string

IsCommitted

true if Commit() has been called.

public bool IsCommitted { get; }

Property Value

bool

WritePath

The temporary file path to write to.

public string WritePath { get; }

Property Value

string

Methods

Commit()

Allows the new file to be deployed upon Dispose().

public void Commit()

Dispose()

Replaces DestinationPath with the contents of WritePath.

public void Dispose()

See Also