using System; namespace SabreTools.IO.Extensions { public static class ByteArrayExtensions { /// /// Align the array position to a byte-size boundary /// /// Input array to try aligning /// Offset into the byte array /// Number of bytes to align on /// True if the array could be aligned, false otherwise public static bool AlignToBoundary(this byte[]? input, ref int offset, byte alignment) { // If the array is invalid if (input is null || input.Length == 0) return false; // If already at the end of the array if (offset >= input.Length) return false; // Align the stream position while (offset % alignment != 0 && offset < input.Length) { offset++; } // Return if the alignment completed return offset % alignment == 0; } /// /// Indicates whether the specified array is null or has a length of zero /// public static bool IsNullOrEmpty(this Array? array) { return array is null || array.Length == 0; } } }