namespace Uwaa.PNG; /// /// The header for a data chunk in a PNG file. /// public readonly struct ChunkHeader { /// /// The position/start of the chunk header within the stream. /// public long Position { get; } /// /// The length of the chunk in bytes. /// public int Length { get; } /// /// The name of the chunk, uppercase first letter means the chunk is critical (vs. ancillary). /// public string Name { get; } /// /// Whether the chunk is critical (must be read by all readers) or ancillary (may be ignored). /// public bool IsCritical => char.IsUpper(Name[0]); /// /// A public chunk is one that is defined in the International Standard or is registered in the list of public chunk types maintained by the Registration Authority. /// Applications can also define private (unregistered) chunk types for their own purposes. /// public bool IsPublic => char.IsUpper(Name[1]); /// /// Whether the (if unrecognized) chunk is safe to copy. /// public bool IsSafeToCopy => char.IsUpper(Name[3]); /// /// Create a new . /// public ChunkHeader(long position, int length, string name) { if (length < 0) { throw new ArgumentException($"Length less than zero ({length}) encountered when reading chunk at position {position}."); } Position = position; Length = length; Name = name; } public override string ToString() { return $"{Name} at {Position} (length: {Length})."; } }