mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-10-01 11:12:19 +00:00
This omits anything that relies on caching, at the moment. There is no easy way of creating a cache for the required pieces in the static context of the extensions.
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System;
|
|
using SabreTools.Models.CFB;
|
|
|
|
namespace SabreTools.Serialization
|
|
{
|
|
public static partial class Extensions
|
|
{
|
|
/// <summary>
|
|
/// Sector size in bytes
|
|
/// </summary>
|
|
/// <param name="binary">Binary model to derive from</param>
|
|
/// <returns>Sector size on success, -1 on error</returns>
|
|
public static long SectorSize(this Binary binary)
|
|
{
|
|
// If we have an invalid header
|
|
if (binary.Header?.SectorShift == null)
|
|
return -1;
|
|
|
|
return (long)Math.Pow(2, binary.Header.SectorShift);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mini sector size in bytes
|
|
/// </summary>
|
|
/// <param name="binary">Binary model to derive from</param>
|
|
/// <returns>Sector size on success, -1 on error</returns>
|
|
public static long MiniSectorSize(this Binary binary)
|
|
{
|
|
// If we have an invalid header
|
|
if (binary.Header?.SectorShift == null)
|
|
return -1;
|
|
|
|
return (long)Math.Pow(2, binary.Header.MiniSectorShift);
|
|
}
|
|
}
|
|
} |