Example #1
0
        internal IEnumerable <StorageData <T> > ReadOnlyEnumerate()
        {
            // MGREC files may not exist

            //// the total number of records
            //long count = _recfileread.Length >> 3;

            //for (long i = 0; i < count; i++)
            //{
            //    StorageItem<T> meta;
            //    byte[] data = ReadBytes(i, out meta);
            //    StorageData<T> sd = new StorageData<T>();
            //    sd.meta = meta;
            //    if (meta.dataLength > 0)
            //        sd.data = data;

            //    yield return sd;
            //}

            long offset = _fileheader.Length;// start; // skip header
            long size   = _dataread.Length;

            while (offset < size)
            {
                StorageData <T> sd = new StorageData <T>();
                lock (_readlock)
                {
                    _dataread.Seek(offset, SeekOrigin.Begin);
                    int             metalen = 0;
                    StorageItem <T> meta    = ReadMetaData(_dataread, out metalen);
                    offset += metalen;

                    sd.meta = meta;
                    if (meta.dataLength > 0)
                    {
                        byte[] data = new byte[meta.dataLength];
                        _dataread.Read(data, 0, meta.dataLength);
                        sd.data = data;
                    }
                    offset += meta.dataLength;
                }
                yield return(sd);
            }
        }
Example #2
0
 internal IEnumerable <StorageData> Enumerate()
 {
     lock (_lock)
     {
         long offset = 6;
         long size   = _dataread.Length;
         while (offset < size)
         {
             // skip header
             _dataread.Seek(offset, SeekOrigin.Begin);
             var hdr = new byte[_rowheader.Length];
             // read header
             _dataread.Read(hdr, 0, _rowheader.Length);
             offset += hdr.Length;
             if (CheckHeader(hdr))
             {
                 var sd = new StorageData {
                     isDeleted = IsDeleted(hdr)
                 };
                 byte kl    = hdr[3];
                 var  kbyte = new byte[kl];
                 offset += kl;
                 _dataread.Read(kbyte, 0, kl);
                 sd.Key = kbyte;
                 int dl   = Helper.ToInt32(hdr, (int)HDR_POS.DataLength);
                 var data = new byte[dl];
                 // read data block
                 _dataread.Read(data, 0, dl);
                 sd.Data = data;
                 offset += dl;
                 yield return(sd);
             }
             else
             {
                 throw new Exception("Data read failed");
             }
         }
     }
 }