SNAP Library 2.2, Developer Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
zipfl.h
Go to the documentation of this file.
00001 #ifndef zipfl_h
00002 #define zipfl_h
00003 
00004 //#//////////////////////////////////////////////
00014 // Obsolete note (RS 2014/01/29): You can only load .gz files of uncompressed size <2GB. If you load some other format (like .bz2 or rar) there is no such limitation.
00015 class TZipIn : public TSIn {
00016 public:
00017   static TStr SevenZipPath;
00018 private:
00019   static TStrStrH FExtToCmdH;
00020   static const int MxBfL;
00021   #ifdef GLib_WIN
00022     HANDLE ZipStdoutRd, ZipStdoutWr;
00023   #else 
00024     FILE* ZipStdoutRd, *ZipStdoutWr;
00025   #endif
00026   uint64 FLen, CurFPos;
00027   char* Bf;
00028   int BfC, BfL;
00029 private:
00030   void FillBf();
00031   int FindEol(int& BfN);
00032   void CreateZipProcess(const TStr& Cmd, const TStr& ZipFNm);
00033   static void FillFExtToCmdH();
00034 private:
00035   TZipIn();
00036   TZipIn(const TZipIn&);
00037   TZipIn& operator=(const TZipIn&);
00038 public:
00039   TZipIn(const TStr& FNm);
00040   TZipIn(const TStr& FNm, bool& OpenedP);
00041   static PSIn New(const TStr& FNm);
00042   static PSIn New(const TStr& FNm, bool& OpenedP);
00043   ~TZipIn();
00044 
00045   bool Eof() { return CurFPos==FLen && BfC==BfL; }
00046   int Len() const { return int(FLen-CurFPos+BfL-BfC); }
00047   char GetCh() { if (BfC==BfL){FillBf();} return Bf[BfC++]; }
00048   char PeekCh() { if (BfC==BfL){FillBf();} return Bf[BfC]; }
00049   int GetBf(const void* LBf, const TSize& LBfL);
00050   bool GetNextLnBf(TChA& LnChA);
00051 
00052   uint64 GetFLen() const { return FLen; }
00053   uint64 GetCurFPos() const { return CurFPos; }
00054 
00056   static bool IsZipFNm(const TStr& FNm) { return IsZipExt(FNm.GetFExt()); }
00058   static bool IsZipExt(const TStr& FNmExt);
00060   static TStr GetCmd(const TStr& ZipFNm);
00062   static uint64 GetFLen(const TStr& ZipFNm);
00063   static PSIn NewIfZip(const TStr& FNm) { return IsZipFNm(FNm) ? New(FNm) : TFIn::New(FNm); }
00064 };
00065 
00066 //#//////////////////////////////////////////////
00074 class TZipOut : public TSOut{
00075 private:
00076   static const TSize MxBfL;
00077   static TStrStrH FExtToCmdH;
00078   #ifdef GLib_WIN
00079     HANDLE ZipStdinRd, ZipStdinWr;
00080   #else 
00081     FILE *ZipStdinRd, *ZipStdinWr;
00082   #endif
00083   char* Bf;
00084   TSize BfL;
00085 private:
00086   void FlushBf();
00087   void CreateZipProcess(const TStr& Cmd, const TStr& ZipFNm);
00088   static void FillFExtToCmdH();
00089 private:
00090   TZipOut();
00091   TZipOut(const TZipOut&);
00092   TZipOut& operator=(const TZipOut&);
00093 public:
00094   TZipOut(const TStr& _FNm);
00095   static PSOut New(const TStr& FNm);
00096   ~TZipOut();
00097 
00098   int PutCh(const char& Ch);
00099   int PutBf(const void* LBf, const TSize& LBfL);
00100   void Flush();
00101 
00103   static bool IsZipFNm(const TStr& FNm) { return IsZipExt(FNm.GetFExt()); }
00105   static bool IsZipExt(const TStr& FNmExt);
00107   static TStr GetCmd(const TStr& ZipFNm);
00108   static PSOut NewIfZip(const TStr& FNm) { return IsZipFNm(FNm) ? New(FNm) : TFOut::New(FNm); }
00109 };
00110 
00111 #endif