Advertisement
tolikpunkoff

IsGZip (detecting gzip archive)

May 3rd, 2018
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. public bool IsGZip(string filename)
  2.         {
  3.             byte[] buf = null;
  4.             try
  5.             {
  6.                 buf = File.ReadAllBytes(filename);
  7.             }
  8.             catch
  9.             {
  10.                 return false;
  11.             }
  12.  
  13.             if (buf.Length < 4) return false;
  14.  
  15.             if ((buf[0] == 0x1F) && (buf[1] == 0x8B) &&
  16.                 (buf[2] == 0x08) && (buf[3] == 0x00))
  17.                 return true;
  18.  
  19.             return false;
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement