The size of the sectors in a compound file is a function of the version. In a version three compound file the sector size is 512 bytes. In a version four compound file the sector size is 4096 bytes.
If a compound file contains a large number of stream objects that are smaller than a sector, and/or whose last part only partially fills a sector than there can be a considerable amount of wasted space.
To help avoid this stream objects below a certain size may be stored as a series of much smaller 64 byte sectors instead.
These sectors are in turn stored as the contents of an internal stream called the ‘mini stream’. This stream has an associated file allocation table, the ‘mini FAT’.
The mini FAT like the FAT is stored in sectors. Unlike the FAT the sector index chain for the Mini FAT is stored in the FAT.
Having read the FAT we can now read the mini FAT.
The starting sector and the number of sectors are specified by the
firstMiniFATSector
and
nMiniFATSectors
fields in the header
We can read the mini FAT using readFAT
since the structure of the mini FAT is identical to that of the FAT.
private func readMiniFAT(
header:
FileHeader,
nEntriesPerSector:
Int,
fat:
FileAllocationTable,
sectors:
SectorSource) -> FileAllocationTable?
{
if let sequence = fat.sequence(header.firstMiniFATSector)
{
return
readFAT(
header.nMiniFATSectors,
nEntriesPerSector:
nEntriesPerSector,
sequence:
sequence,
sectors:
sectors)
}
else
{
return nil
}
}
Copyright (c) 2014 By Simon Lewis. All Rights Reserved.
Unauthorized use and/or duplication of this material without express and written permission from this blog’s author and owner Simon Lewis is strictly prohibited.
Excerpts and links may be used, provided that full and clear credit is given to Simon Lewis and justanapplication.wordpress.com with appropriate and specific direction to the original content.
Leave a Reply