daily pastebin goal
18%
SHARE
TWEET

IsGZip (detecting gzip archive) v2

tolikpunkoff May 6th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top