/* This file is part of libmspack.
* (C) 2003-2018 Stuart Caie.
*
* libmspack is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License (LGPL) version 2.1
*
* For further details, see the file COPYING.LIB distributed with libmspack
*/
using System;
namespace LibMSPackSharp.CAB
{
internal class _FolderHeader
{
#region Fields
///
/// Cabinet offset of first datablock
///
/// 0x00
public uint DataOffset { get; internal set; }
///
/// The total number of data blocks used by this folder. This includes
/// data blocks present in other files, if this folder spans more than
/// one cabinet.
///
/// 0x04
public ushort NumBlocks { get; internal set; }
///
/// The compression format used by this folder.
///
/// The macro MSCABD_COMP_METHOD() should be used on this field to get
/// the algorithm used. The macro MSCABD_COMP_LEVEL() should be used to get
/// the "compression level".
///
/// 0x06
public CompressionType CompType { get; private set; }
///
/// Size of the Folder header in bytes
///
public const int Size = 0x08;
#endregion
///
/// Private constructor
///
private _FolderHeader() { }
///
/// Create a _FolderHeader from a byte array, if possible
///
public static Error Create(byte[] buffer, out _FolderHeader header)
{
header = null;
if (buffer == null || buffer.Length < Size)
return Error.MSPACK_ERR_READ;
header = new _FolderHeader();
header.DataOffset = BitConverter.ToUInt32(buffer, 0x00);
header.NumBlocks = BitConverter.ToUInt16(buffer, 0x04);
header.CompType = (CompressionType)BitConverter.ToUInt16(buffer, 0x06);
return Error.MSPACK_ERR_OK;
}
}
}