From 62764fee9a57ac4bfce114335c1f71326bf91005 Mon Sep 17 00:00:00 2001 From: BahaBulle Date: Wed, 18 May 2016 16:43:25 +0200 Subject: [PATCH] Add padding method in MemoryStream --- Hack.Xenosaga/Common/Extension.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Hack.Xenosaga/Common/Extension.cs b/Hack.Xenosaga/Common/Extension.cs index 3df801f..3a5099c 100644 --- a/Hack.Xenosaga/Common/Extension.cs +++ b/Hack.Xenosaga/Common/Extension.cs @@ -40,5 +40,21 @@ namespace Hack.Xenosaga.Common return value; } + + /// + /// Pad a MemoryStream with a byte + /// + /// Modulo to use for the padding (default: 4) + /// Value of the byte (default: 0) + public static void Padding(this MemoryStream ms, int modulo = 4, byte value = 0) + { + long size = ms.Length; + + while (size % modulo != 0) + { + ms.WriteByte(value); + size++; + } + } } }