public unsafe override int ReadForward(Stream s, byte[] bulk, BlockDBEntry *entriesPtr) { long pos = s.Position; // Version 2 expects all chunks to be aligned to 4096 bytes if (pos < BlockSize) { s.Position = BlockSize; pos = BlockSize; } long remaining = s.Length - pos; if (remaining == 0) { return(0); } int bytes = (int)Math.Min(remaining, BlockSize); int offset = bulk.Length - BlockSize; // NOTE: bulk and entriesPtr point to same thing // But we read into the end of the bulk array, thus the entriesPtr pointing // to start of array never ends up overlapping with the data being read BlockDBFile.ReadFully(s, bulk, offset, bytes); return(DecompressChunk(bulk, offset, entriesPtr)); }
public unsafe override int ReadForward(Stream s, byte[] bulk, BlockDBEntry *entriesPtr) { long remaining = (s.Length - s.Position) / EntrySize; int count = (int)Math.Min(remaining, BulkEntries); if (count > 0) { BlockDBFile.ReadFully(s, bulk, 0, count * EntrySize); } return(count); }
public override long CountEntries(Stream s) { byte[] data = new byte[8]; s.Position = 16; BlockDBFile.ReadFully(s, data, 0, data.Length); uint lo = (uint)ReadInt32(data, 0); uint hi = (uint)ReadInt32(data, 4); return((long)((ulong)lo | ((ulong)hi << 32))); }
public unsafe override int ReadBackward(Stream s, byte[] bulk, BlockDBEntry *entriesPtr) { long pos = s.Position; long remaining = (pos / EntrySize) - HeaderEntries; int count = (int)Math.Min(remaining, BulkEntries); if (count > 0) { pos -= count * EntrySize; s.Position = pos; BlockDBFile.ReadFully(s, bulk, 0, count * EntrySize); s.Position = pos; // set correct position for next backward read } return(count); }
public unsafe override int ReadBackward(Stream s, byte[] bulk, BlockDBEntry *entriesPtr) { long pos = s.Position; if (pos > BlockSize) { int bytes = (int)Math.Min(pos - BlockSize, BlockSize); int offset = bulk.Length - BlockSize; pos -= bytes; s.Position = pos; BlockDBFile.ReadFully(s, bulk, offset, bytes); s.Position = pos; // set correct position for next backward read return(DecompressChunk(bulk, offset, entriesPtr)); } return(0); }