diff options
author | vnugent <public@vaughnnugent.com> | 2024-02-29 21:23:26 -0500 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-02-29 21:23:26 -0500 |
commit | b679ddd4e647ac915febd0d5a5e488a1e8e48842 (patch) | |
tree | cf414be9a53342e8d59194198cde5bf3c2187fc1 /lib/Utils/src/IO | |
parent | 2b1314c1475e7e1831c691cf349cb89c66fa320c (diff) |
Squashed commit of the following:
commit 231e26e5c6731e6e156d7c0591518e84a3b82f5a
Author: vnugent <public@vaughnnugent.com>
Date: Thu Feb 29 20:59:42 2024 -0500
fix: #5 find and patch Windows compression bug and some deployment
commit d0bfe14e0a0e27172b8dd41f468265e651784837
Author: vnugent <public@vaughnnugent.com>
Date: Wed Feb 21 21:39:19 2024 -0500
fix: #4 fix readme licensing message for accuracy
commit 6f37f152fcd105e40af6689192a36b87eda95f51
Author: vnugent <public@vaughnnugent.com>
Date: Wed Feb 21 21:37:55 2024 -0500
fix: jwt hashalg sizing and public api for hashalg sizes
Diffstat (limited to 'lib/Utils/src/IO')
-rw-r--r-- | lib/Utils/src/IO/VnMemoryStream.cs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Utils/src/IO/VnMemoryStream.cs b/lib/Utils/src/IO/VnMemoryStream.cs index ed8ed5a..ada2c64 100644 --- a/lib/Utils/src/IO/VnMemoryStream.cs +++ b/lib/Utils/src/IO/VnMemoryStream.cs @@ -88,6 +88,7 @@ namespace VNLib.Utils.IO /// <returns>The readonly stream</returns> public static VnMemoryStream CreateReadonly(VnMemoryStream stream) { + ArgumentNullException.ThrowIfNull(stream); //Set the readonly flag stream._isReadonly = true; //Return the stream @@ -528,10 +529,19 @@ namespace VNLib.Utils.IO /// <exception cref="OutOfMemoryException"></exception> public byte[] ToArray() { - //Alloc a new array of the size of the internal buffer, may be 64 bit large block - byte[] data = new byte[_length]; - - //Copy the internal buffer to the new array + byte[] data; + + if (_length < Int32.MaxValue) + { + //Alloc uninialized, since were going to overwite it anyway + data = GC.AllocateUninitializedArray<byte>((int)_length, false); + } + else + { + //Use new opperator if larger than 32bit + data = new byte[_length]; + } + MemoryUtil.CopyArray(_buffer, 0, data, 0, (nuint)_length); return data; |