Advertisement
tolikpunkoff

IsGZip (detecting gzip archive) v2

May 6th, 2018
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. public bool IsGZip(string filename)
  2.         {
  3.             int signlen = 4;
  4.             int count = 0;
  5.             byte[] buf = new byte[signlen];
  6.             FileStream readStream = null;
  7.             try
  8.             {
  9.                 readStream = new FileStream(filename, FileMode.Open);
  10.                 count = readStream.Read(buf, 0, signlen);
  11.             }
  12.             catch
  13.             {
  14.                 return false;
  15.             }
  16.             readStream.Close();
  17.  
  18.             if (count < 4) return false;
  19.  
  20.             if ((buf[0] == 0x1F) && (buf[1] == 0x8B) &&
  21.                 (buf[2] == 0x08) && (buf[3] == 0x00))
  22.                 return true;
  23.  
  24.             return false;
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement