SpawnDev.PatchStreams 1.0.3

SpawnDev.PatchStreams

NuGet version

PatchStream : Stream

  • PatchStream inherits from Stream making it easy to use with countless existing libraries that can work with Streams.
  • It is a readable, writable stream that, when modified, does not modify any source data or data added to it, but instead creates patches to represent the data changes.
  • Supports data deletion, insertion, overwriting, slicing, splicing, undo/redo, restore points, partial data views, multi-stream read-only sources, and multiple stream insertion.
  • All modifications to a PatchStream are saved in patches which can be undone and redone as fast as changing a single integer value
  • Restore points can be set at any point and restored easily to make undo/redo easier.
  • Low memory usage and blazing fast modifications.
  • IMPORTANT - Once data has been added to a PatchStream it should not be modified in any way. Modify the PatchStream itself.

The below code is a basic demonstration of PatchStream reading writing, inserting, deleting, restore point usage, and an undo.

using SpawnDev.PatchStreams;

// Create a new PatchStream with or without source data.
// Source data and data added to PatchStream should not be modified once it is added
var patchStream = new PatchStream(new MemoryStream());
patchStream.Write("world!");
// patchStream data is now "world!"

// prepend "Hello "
patchStream.InsertWrites = true;
patchStream.Position = 0;
patchStream.Write("Hello ");

// patchStream data is now "Hello world!"
Console.WriteLine(patchStream.ToString(true));

// set restore point for the current patch. we can revert back later
patchStream.RestorePoint = true;

// overwrite "world!" with "DotNet!"
patchStream.InsertWrites = false;
patchStream.Position = 6;
patchStream.Write("DotNet!");

// patchStream data is now "Hello DotNet!"
Console.WriteLine(patchStream.ToString(true));

// prepend "Presenting: "
patchStream.InsertWrites = true;
patchStream.Position = 0;
patchStream.Write("Presenting: ");

// delete data
patchStream.Delete();

// patchStream data is now "" and patchStream.Length == 0
Console.WriteLine("Empty ->" + patchStream.ToString(true));

// undo the last modification, which was a Delete()
patchStream.Undo();

// patchStream data is now "Presenting: Hello DotNet!"
Console.WriteLine(patchStream.ToString(true));

// go to the most recent restore point
patchStream.RestorePointUndo();

// patchStream data is now "Hello world!"
Console.WriteLine(patchStream.ToString(true));

// Flush current patch stream to the original source stream (for single, writable source streams only)
patchStream.Flush();

Showing the top 20 packages that depend on SpawnDev.PatchStreams.

Packages Downloads
SpawnDev.EBML
An extendable .Net library for reading and writing Extensible Binary Meta Language (aka EBML) document streams. Includes schema for Matroska and WebM.
23
SpawnDev.EBML
An extendable .Net library for reading and writing Extensible Binary Meta Language (aka EBML) document streams. Includes schema for Matroska and WebM.
19

.NET 6.0

  • No dependencies.

.NET 7.0

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET 9.0

  • No dependencies.

Version Downloads Last updated
1.0.6 21 04/30/2026
1.0.5 17 04/30/2026
1.0.4 15 04/30/2026
1.0.3 16 04/30/2026
1.0.2 18 04/30/2026
1.0.1 14 04/30/2026
1.0.0 14 04/30/2026