Jelajahi Sumber

Add capacity ctor and `SetLength` to MemoryStream

disarray2077 2 tahun lalu
induk
melakukan
4a0ec6ce8c
1 mengubah file dengan 18 tambahan dan 0 penghapusan
  1. 18 0
      BeefLibs/corlib/src/IO/MemoryStream.bf

+ 18 - 0
BeefLibs/corlib/src/IO/MemoryStream.bf

@@ -50,6 +50,12 @@ namespace System.IO
 			mOwns = true;
 			mOwns = true;
 			mMemory = new List<uint8>();
 			mMemory = new List<uint8>();
 		}
 		}
+		
+		public this(int capacity)
+                {
+                        mOwns = true;
+                        mMemory = new List<uint8>(capacity);
+                }
 
 
 		public this(List<uint8> memory, bool owns = true)
 		public this(List<uint8> memory, bool owns = true)
 		{
 		{
@@ -90,5 +96,17 @@ namespace System.IO
 		{
 		{
 			return .Ok;
 			return .Ok;
 		}
 		}
+		
+		public override Result<void> SetLength(int64 length)
+                {
+                        Debug.Assert(mOwns);
+
+                        mMemory.Resize((.)length);
+
+                        if (Position >= length)
+                                Position = Length;
+
+                        return .Ok;
+                }
 	}
 	}
 }
 }