Warning, /include/Geant4/tools/gzip is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_gzip
0005 #define tools_gzip
0006
0007 #include "signature"
0008
0009 namespace tools {
0010 namespace file {
0011
0012 inline bool is_gzip(const std::string& a_file,bool& a_is){
0013 unsigned char head[4];
0014 {unsigned int num = 4;
0015 if(!signature(a_file,head,num)) {a_is = false;return false;}
0016 if(num!=4) {a_is = false;return true;}}
0017 if(head[0]!=31) {a_is = false;return true;}
0018 if(head[1]!=139) {a_is = false;return true;}
0019 //if(head[2]!=8) {a_is = false;return true;}
0020 //if(head[3]!=8) {a_is = false;return true;}
0021 a_is = true;
0022 return true;
0023 }
0024
0025 inline bool gzip_usize(const std::string& a_file,unsigned int& a_usz){
0026 bool is;
0027 if(!is_gzip(a_file,is)) {a_usz=0;return false;}
0028 if(!is) {a_usz=0;return false;}
0029 FILE* file = ::fopen(a_file.c_str(),"rb");
0030 if(!file) {a_usz=0;return false;}
0031 ::fseek(file,-4,SEEK_END);
0032 unsigned char buf[4];
0033 size_t n = ::fread(buf,1,4,file);
0034 ::fclose(file);
0035 if(n!=4) {a_usz=0;return false;}
0036 unsigned int b4 = buf[0];
0037 unsigned int b3 = buf[1];
0038 unsigned int b2 = buf[2];
0039 unsigned int b1 = buf[3];
0040 a_usz = (b1 << 24) | ((b2 << 16) + (b3 << 8) + b4);
0041 return true;
0042 }
0043
0044 }}
0045
0046 #endif