Esempio n. 1
0
        internal byte[] ReadFileData(GranuleChain granulechain, int lastsectorsize)
        {
            int filesize = GetFileSize(granulechain, lastsectorsize);
            var data = new byte[filesize];
            int dataoffset = 0;
            int granulecount = granulechain.granules.Length;
            int sectorcount = (granulecount - 1)*GranuleSectors + granulechain.sectors;         // The total number of sectors holding file payload data

            for (int i = 0; i < granulecount; i++ )                                             // Once for each granule
            {
                int lsn = GranuleToLsn(granulechain.granules[i]);
                for (int j=0; j < Math.Min(GranuleSectors,sectorcount); j++)                    // Once for each granule sector, paying special attention to the last granule
                {
                    var sector = ReadSector(lsn++);
                    int sectorsize = Math.Min(SectorSize, filesize);                       // Pay special attention to the last sector
                    Array.Copy(sector, 0, data, dataoffset, sectorsize);
                    dataoffset += sectorsize;
                    filesize -= sectorsize;
                }
            }
            return data;
        }
Esempio n. 2
0
 internal int GetFileSize(GranuleChain granulechain, int lastsectorsize)
 {
     int completegranules = Math.Max(0, granulechain.granules.Length - 1) * GranuleSize;
     int lastgranule = (granulechain.sectors == 0)
                           ? 0
                           : (granulechain.sectors - 1)*SectorSize + lastsectorsize;
     return completegranules + lastgranule;
 }