private byte[] ReadInternal(int ix, long maxlen) { TheFile.Position = BitmapToPos(ix); var sectortype = (Store.SectorTypes)StreamUtils.ReadInt8(TheFile); if (sectortype != Store.SectorTypes.Data) { throw new Exception("Trying to read in non data area"); } var nextsector = StreamUtils.ReadInt32(TheFile); var totallen = StreamUtils.ReadInt64(TheFile); if (maxlen > 0) { totallen = Math.Min(totallen, maxlen); } var result = new byte[totallen]; var resultpos = 0; var buflen = FirstSectorDataSize; while (resultpos < totallen) { var len = (int)Math.Min(totallen - resultpos, buflen); var readlen = TheFile.Read(result, resultpos, len); if (nextsector == LAST_SECTOR_IN_CHAIN) { var curlen = resultpos + readlen; if (totallen > curlen) { DebugUtils.LogWarning("Store: Warning! Stored length of the chain is faulty!"); return(result.Copy(0, curlen)); } break; } TheFile.Position = BitmapToPos(nextsector); var stype = (Store.SectorTypes)StreamUtils.ReadInt8(TheFile); if (stype != Store.SectorTypes.Continuation) { throw new Exception("Trying to read in non data area"); } nextsector = StreamUtils.ReadInt32(TheFile); resultpos += readlen; buflen = SectorDataSize; } return(result); }
public StoreStream(Store store, int ix, long offset) { TheStore = store; Ix = ix; if (offset < 0) { throw new ArgumentException("offset must be >= 0!"); } PositionOffset = offset; var file = TheStore.TheFile; // Get current state file.Position = TheStore.BitmapToPos(ix); var sectortype = (Store.SectorTypes)StreamUtils.ReadInt8(file); if (sectortype != Store.SectorTypes.Data) { throw new Exception("Trying to read in non data area"); } var nextsector = StreamUtils.ReadInt32(file); var CurrentLength = StreamUtils.ReadInt64(file); while (sectortype == SectorTypes.Data || sectortype == SectorTypes.Continuation) { Sectors.Add(ix); if (nextsector == LAST_SECTOR_IN_CHAIN) { break; } file.Position = TheStore.BitmapToPos(nextsector); ix = nextsector; sectortype = (Store.SectorTypes)StreamUtils.ReadInt8(file); if (sectortype != Store.SectorTypes.Data && sectortype != SectorTypes.Continuation) { throw new Exception("Trying to read in non data area"); } nextsector = StreamUtils.ReadInt32(file); } }
public long GetDataLength(int ix) { if (!Bits[ix]) { return(0); // Free } TheFile.Position = BitmapToPos(ix); var sectortype = StreamUtils.ReadInt8(TheFile); if ((Store.SectorTypes)sectortype != Store.SectorTypes.Data) { return(0); } var nextsector = StreamUtils.ReadInt32(TheFile); return(StreamUtils.ReadInt64(TheFile)); }