Advertisement
tolikpunkoff

Sxypex Geo DB reading functions

Sep 10th, 2018
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1.         //ползалка по файлу БД
  2.         public bool Seek(long Offset, SeekOrigin Origin)
  3.         {
  4.             if (!IsOpen)
  5.             {
  6.                 if (string.IsNullOrEmpty(ErrorMessage))
  7.                 {
  8.                     ErrorMessage = "Database not open";
  9.                 }
  10.                 return false;
  11.             }
  12.  
  13.             try
  14.             {
  15.                 SxStream.Seek(Offset, Origin);
  16.             }
  17.             catch (Exception ex)
  18.             {
  19.                 ErrorMessage = ex.Message;
  20.                 return false;
  21.             }
  22.             return true;
  23.         }
  24.  
  25.         public byte[] ReadBytes(int Count)
  26.         {
  27.             if (!IsOpen)
  28.             {
  29.                 if (string.IsNullOrEmpty(ErrorMessage))
  30.                 {
  31.                     ErrorMessage = "Database not open";
  32.                 }
  33.                 return null;
  34.             }
  35.            
  36.             return ReadBytes(SxStream, Count);
  37.         }
  38.        
  39.         private byte[] ReadBytes(FileStream FST, int Count)
  40.         {
  41.             byte[] buf = new byte[Count];
  42.             int readedBytes = 0;
  43.             try
  44.             {
  45.                 readedBytes = FST.Read(buf, 0, Count);
  46.             }
  47.             catch (Exception ex)
  48.             {
  49.                 ErrorMessage = ex.Message;
  50.                 return null;
  51.             }
  52.             if (readedBytes != Count)
  53.             {
  54.                 ErrorMessage = "Format error";
  55.                 return null;
  56.             }
  57.  
  58.             return buf;
  59.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement