wabbajack/Wabbajack.Common/ByteArrayExtensions.cs

21 lines
493 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Common;
public static class ByteArrayExtensions
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public static byte[] ConcatArrays(this IReadOnlyCollection<byte[]> arrays)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
var outArray = new byte[arrays.Sum(a => a.Length)];
var offset = 0;
foreach (var arr in arrays)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
Array.Copy(arr, 0, outArray, offset, arr.Length);
offset += arr.Length;
2021-09-27 12:42:46 +00:00
}
2021-10-23 16:51:17 +00:00
return outArray;
2021-09-27 12:42:46 +00:00
}
}