SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TZipIn Class Reference

#include <zipfl.h>

Inherits TSIn.

Public Member Functions

 TZipIn (const TStr &FNm)
 
 TZipIn (const TStr &FNm, bool &OpenedP)
 
 ~TZipIn ()
 
bool Eof ()
 
int Len () const
 
char GetCh ()
 
char PeekCh ()
 
int GetBf (const void *LBf, const TSize &LBfL)
 
bool GetNextLnBf (TChA &LnChA)
 
uint64 GetFLen () const
 
uint64 GetCurFPos () const
 
- Public Member Functions inherited from TSIn
 TSIn ()
 
 TSIn (const TStr &Str)
 
virtual ~TSIn ()
 
virtual void Reset ()
 
bool IsFastMode () const
 
void SetFastMode (const bool &_FastMode)
 
virtual void LoadCs ()
 
void LoadBf (const void *Bf, const TSize &BfL)
 
void * LoadNewBf (const int &BfL)
 
void Load (bool &Bool)
 
void Load (uchar &UCh)
 
void Load (char &Ch)
 
void Load (short &Short)
 
void Load (ushort &UShort)
 
void Load (int &Int)
 
void Load (uint &UInt)
 
void Load (int64 &Int)
 
void Load (uint64 &UInt)
 
void Load (double &Flt)
 
void Load (sdouble &SFlt)
 
void Load (ldouble &LFlt)
 
void Load (char *&CStr, const int &MxCStrLen, const int &CStrLen)
 
void Load (char *&CStr)
 
TSInoperator>> (bool &Bool)
 
TSInoperator>> (uchar &UCh)
 
TSInoperator>> (char &Ch)
 
TSInoperator>> (short &Sh)
 
TSInoperator>> (ushort &USh)
 
TSInoperator>> (int &Int)
 
TSInoperator>> (uint &UInt)
 
TSInoperator>> (int64 &Int)
 
TSInoperator>> (uint64 &UInt)
 
TSInoperator>> (float &Flt)
 
TSInoperator>> (double &Double)
 
TSInoperator>> (long double &LDouble)
 
bool GetNextLn (TStr &LnStr)
 
bool GetNextLn (TChA &LnChA)
 
- Public Member Functions inherited from TSBase
 TSBase (const TSStr &Nm)
 
virtual ~TSBase ()
 
virtual TStr GetSNm () const
 

Static Public Member Functions

static PSIn New (const TStr &FNm)
 
static PSIn New (const TStr &FNm, bool &OpenedP)
 
static bool IsZipFNm (const TStr &FNm)
 Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2). More...
 
static bool IsZipExt (const TStr &FNmExt)
 Check whether the file extension FNmExt is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2). More...
 
static TStr GetCmd (const TStr &ZipFNm)
 Return a command-line string that is executed in order to decompress a file to standard output. More...
 
static uint64 GetFLen (const TStr &ZipFNm)
 Return the uncompressed size (in bytes) of the compressed file ZipFNm. More...
 
static PSIn NewIfZip (const TStr &FNm)
 

Static Public Attributes

static TStr SevenZipPath = "/usr/bin"
 
- Static Public Attributes inherited from TSIn
static const TPt< TSInStdIn =PSIn(new TStdIn())
 

Private Member Functions

void FillBf ()
 
int FindEol (int &BfN)
 
void CreateZipProcess (const TStr &Cmd, const TStr &ZipFNm)
 
 TZipIn ()
 
 TZipIn (const TZipIn &)
 
TZipInoperator= (const TZipIn &)
 

Static Private Member Functions

static void FillFExtToCmdH ()
 

Private Attributes

FILE * ZipStdoutRd
 
FILE * ZipStdoutWr
 
uint64 FLen
 
uint64 CurFPos
 
char * Bf
 
int BfC
 
int BfL
 

Static Private Attributes

static TStrStrH FExtToCmdH
 
static const int MxBfL =32*1024
 

Additional Inherited Members

- Protected Attributes inherited from TSBase
TCRef CRef
 
TSStr SNm
 
TCs Cs
 

Detailed Description

Compressed File Input Stream. The class reads from a compressed file without explicitly uncompressing it. This is eachieved by running external 7ZIP program which uncompresses to standard output, which is then piped to TZipFl. The class requires 7ZIP to be installed on the machine. Go to http://www.7-zip.org to install the software. 7z (7z.exe) is an executable and can decompress the following formats: .gz, .7z, .rar, .zip, .cab, .arj. bzip2. The class TZipIn expects that '7z' ('7z.exe') is in the working path. Make sure you can execute '7z e -y -bd -so <FILENAME>' For 7z to work properly you need both the 7z executable and the directory 'Codecs'. Use TZipIn::SevenZipPath to set the path to 7z executable.

NOTE: Current implementation of TZipIn supports only .zip format, other compression formats are not supported.

Definition at line 15 of file zipfl.h.

Constructor & Destructor Documentation

TZipIn::TZipIn ( )
private
TZipIn::TZipIn ( const TZipIn )
private
TZipIn::TZipIn ( const TStr FNm)

Definition at line 65 of file zipfl.cpp.

65  : TSBase(FNm.CStr()), TSIn(FNm), ZipStdoutRd(NULL), ZipStdoutWr(NULL),
66  FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
67  EAssertR(! FNm.Empty(), "Empty file-name.");
68  EAssertR(TFile::Exists(FNm), TStr::Fmt("File %s does not exist", FNm.CStr()).CStr());
69  FLen = 0;
70  // non-zip files not supported, need uncompressed file length information
71  //if (FNm.GetFExt() != ".zip") { //J: changed by Jure on Nov 23 2015
72  if (! IsZipFNm(FNm)) {
73  printf("*** Error: file %s, compression format %s not supported\n", FNm.CStr(), FNm.GetFExt().CStr());
74  EFailR(TStr::Fmt("File %s: compression format %s not supported", FNm.CStr(), FNm.GetFExt().CStr()).CStr());
75  }
76  FLen = TZipIn::GetFLen(FNm);
77  // return for malformed files
78  if (FLen == 0) { return; } // empty file
79  #ifdef GLib_WIN
80  // create pipes
81  SECURITY_ATTRIBUTES saAttr;
82  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
83  saAttr.bInheritHandle = TRUE;
84  saAttr.lpSecurityDescriptor = NULL;
85  // Create a pipe for the child process's STDOUT.
86  const int PipeBufferSz = 32*1024;
87  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed");
88  // Ensure the read handle to the pipe for STDOUT is not inherited.
89  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
90  #else
91  // no implementation needed
92  #endif
93  CreateZipProcess(GetCmd(FNm), FNm);
94  Bf = new char[MxBfL]; BfC = BfL=-1;
95  FillBf();
96 }
int BfL
Definition: zipfl.h:28
FILE * ZipStdoutWr
Definition: zipfl.h:24
static TStr GetCmd(const TStr &ZipFNm)
Return a command-line string that is executed in order to decompress a file to standard output...
Definition: zipfl.cpp:223
TSBase(const TSStr &Nm)
Definition: fl.h:50
static bool Exists(const TStr &FNm)
Definition: fl.cpp:1156
static bool IsZipFNm(const TStr &FNm)
Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
Definition: zipfl.h:56
uint64 CurFPos
Definition: zipfl.h:26
TStr GetFExt() const
Definition: dt.cpp:1421
static const int MxBfL
Definition: zipfl.h:20
char * Bf
Definition: zipfl.h:27
#define EFailR(Reason)
Definition: bd.h:246
FILE * ZipStdoutRd
Definition: zipfl.h:24
TSIn()
Definition: fl.h:65
bool Empty() const
Definition: dt.h:491
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
uint64 FLen
Definition: zipfl.h:26
void FillBf()
Definition: zipfl.cpp:48
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
void CreateZipProcess(const TStr &Cmd, const TStr &ZipFNm)
Definition: zipfl.cpp:18
int BfC
Definition: zipfl.h:28
uint64 GetFLen() const
Definition: zipfl.h:52
char * CStr()
Definition: dt.h:479
TZipIn::TZipIn ( const TStr FNm,
bool &  OpenedP 
)

Definition at line 98 of file zipfl.cpp.

98  : TSBase(FNm.CStr()), TSIn(FNm), ZipStdoutRd(NULL), ZipStdoutWr(NULL),
99  FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
100  EAssertR(! FNm.Empty(), "Empty file-name.");
101  FLen = TZipIn::GetFLen(FNm);
102  OpenedP = TFile::Exists(FNm);
103  if (OpenedP) {
104  #ifdef GLib_WIN
105  SECURITY_ATTRIBUTES saAttr;
106  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
107  saAttr.bInheritHandle = TRUE;
108  saAttr.lpSecurityDescriptor = NULL;
109  // Create a pipe for the child process's STDOUT.
110  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, 0), "Stdout pipe creation failed");
111  // Ensure the read handle to the pipe for STDOUT is not inherited.
112  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
113  #else
114  // no implementation needed
115  #endif
116  CreateZipProcess(GetCmd(FNm.GetFExt()), FNm);
117  Bf = new char[MxBfL]; BfC = BfL=-1;
118  FillBf();
119  }
120 }
int BfL
Definition: zipfl.h:28
FILE * ZipStdoutWr
Definition: zipfl.h:24
static TStr GetCmd(const TStr &ZipFNm)
Return a command-line string that is executed in order to decompress a file to standard output...
Definition: zipfl.cpp:223
TSBase(const TSStr &Nm)
Definition: fl.h:50
static bool Exists(const TStr &FNm)
Definition: fl.cpp:1156
uint64 CurFPos
Definition: zipfl.h:26
TStr GetFExt() const
Definition: dt.cpp:1421
static const int MxBfL
Definition: zipfl.h:20
char * Bf
Definition: zipfl.h:27
FILE * ZipStdoutRd
Definition: zipfl.h:24
TSIn()
Definition: fl.h:65
bool Empty() const
Definition: dt.h:491
uint64 FLen
Definition: zipfl.h:26
void FillBf()
Definition: zipfl.cpp:48
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
void CreateZipProcess(const TStr &Cmd, const TStr &ZipFNm)
Definition: zipfl.cpp:18
int BfC
Definition: zipfl.h:28
uint64 GetFLen() const
Definition: zipfl.h:52
char * CStr()
Definition: dt.h:479
TZipIn::~TZipIn ( )

Definition at line 130 of file zipfl.cpp.

130  {
131  #ifdef GLib_WIN
132  if (ZipStdoutRd != NULL) {
133  EAssertR(CloseHandle(ZipStdoutRd), "Closing read-end of pipe failed"); }
134  if (ZipStdoutWr != NULL) {
135  EAssertR(CloseHandle(ZipStdoutWr)!=0, "Closing write-end of pipe failed"); }
136  #else
137  if (ZipStdoutRd != NULL) {
138  EAssertR(pclose(ZipStdoutRd) != -1, "Closing of the process failed"); }
139  #endif
140  if (Bf != NULL) { delete[] Bf; }
141 }
FILE * ZipStdoutWr
Definition: zipfl.h:24
char * Bf
Definition: zipfl.h:27
FILE * ZipStdoutRd
Definition: zipfl.h:24
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283

Member Function Documentation

void TZipIn::CreateZipProcess ( const TStr Cmd,
const TStr ZipFNm 
)
private

Definition at line 18 of file zipfl.cpp.

18  {
19  const TStr CmdLine = TStr::Fmt("%s %s", Cmd.CStr(), ZipFNm.CStr());
20  #ifdef GLib_WIN
21  PROCESS_INFORMATION piProcInfo;
22  STARTUPINFO siStartInfo;
23  ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION));
24  ZeroMemory( &siStartInfo, sizeof(STARTUPINFO));
25  siStartInfo.cb = sizeof(STARTUPINFO);
26  siStartInfo.hStdOutput = ZipStdoutWr;
27  siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
28  // Create the child process.
29  const BOOL FuncRetn = CreateProcess(NULL,
30  (LPSTR) CmdLine.CStr(), // command line
31  NULL, // process security attributes
32  NULL, // primary thread security attributes
33  TRUE, // handles are inherited
34  0, // creation flags
35  NULL, // use parent's environment
36  NULL, // use parent's current directory
37  &siStartInfo, // STARTUPINFO pointer
38  &piProcInfo); // receives PROCESS_INFORMATION
39  EAssertR(FuncRetn!=0, TStr::Fmt("Can not execute '%s' (Set the TZipIn::SevenZipPath)", CmdLine.CStr()).CStr());
40  CloseHandle(piProcInfo.hProcess);
41  CloseHandle(piProcInfo.hThread);
42  #else
43  ZipStdoutRd = popen((TZipIn::SevenZipPath+"/"+CmdLine).CStr(), "r");
44  EAssertR(ZipStdoutRd, TStr::Fmt("Can not execute '%s' (Set the TZipIn::SevenZipPath)", CmdLine.CStr()).CStr());
45  #endif
46 }
FILE * ZipStdoutWr
Definition: zipfl.h:24
static TStr SevenZipPath
Definition: zipfl.h:17
FILE * ZipStdoutRd
Definition: zipfl.h:24
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * CStr()
Definition: dt.h:479
bool TZipIn::Eof ( )
inlinevirtual

Implements TSIn.

Definition at line 45 of file zipfl.h.

45 { return CurFPos==FLen && BfC==BfL; }
int BfL
Definition: zipfl.h:28
uint64 CurFPos
Definition: zipfl.h:26
uint64 FLen
Definition: zipfl.h:26
int BfC
Definition: zipfl.h:28
void TZipIn::FillBf ( )
private

Definition at line 48 of file zipfl.cpp.

48  {
49  EAssertR(CurFPos < FLen, TStr::Fmt("End of file '%s' reached (CurFPos=%s, FLen=%s).", GetSNm().CStr(), TUInt64(CurFPos).GetStr().CStr(), TUInt64(FLen).GetStr().CStr()));
50  EAssertR((BfC==BfL)/*&&((BfL==-1)||(BfL==MxBfL))*/, "Error reading file '"+GetSNm()+"' (Set the TZipIn::SevenZipPath).");
51  #ifdef GLib_WIN
52  // Read output from the child process
53  DWORD BytesRead;
54  EAssert(ReadFile(ZipStdoutRd, Bf, MxBfL, &BytesRead, NULL) != 0);
55  #else
56  size_t BytesRead = fread(Bf, 1, MxBfL, ZipStdoutRd);
57  EAssert(BytesRead != 0);
58  #endif
59  BfL = (int) BytesRead;
60  CurFPos += BytesRead;
61  EAssertR((BfC!=0)||(BfL!=0), "Error reading file '"+GetSNm()+"' (Set the TZipIn::SevenZipPath).");
62  BfC = 0;
63 }
int BfL
Definition: zipfl.h:28
uint64 CurFPos
Definition: zipfl.h:26
static const int MxBfL
Definition: zipfl.h:20
char * Bf
Definition: zipfl.h:27
FILE * ZipStdoutRd
Definition: zipfl.h:24
#define EAssert(Cond)
Definition: bd.h:280
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
uint64 FLen
Definition: zipfl.h:26
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
virtual TStr GetSNm() const
Definition: fl.cpp:20
int BfC
Definition: zipfl.h:28
Definition: dt.h:1318
void TZipIn::FillFExtToCmdH ( )
staticprivate

Definition at line 204 of file zipfl.cpp.

204  {
205  // 7za decompress: "e -y -bd -so";
206  #ifdef GLib_WIN
207  const char* ZipCmd = "7z.exe e -y -bd -so";
208  #else
209  const char* ZipCmd = "7za e -y -bd -so";
210  #endif
211  if (FExtToCmdH.Empty()) {
212  FExtToCmdH.AddDat(".gz", ZipCmd);
213  FExtToCmdH.AddDat(".7z", ZipCmd);
214  FExtToCmdH.AddDat(".rar", ZipCmd);
215  FExtToCmdH.AddDat(".zip", ZipCmd);
216  FExtToCmdH.AddDat(".cab", ZipCmd);
217  FExtToCmdH.AddDat(".arj", ZipCmd);
218  FExtToCmdH.AddDat(".bzip2", ZipCmd);
219  FExtToCmdH.AddDat(".bz2", ZipCmd);
220  }
221 }
static TStrStrH FExtToCmdH
Definition: zipfl.h:19
bool Empty() const
Definition: hash.h:227
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
int TZipIn::FindEol ( int &  BfN)
private

Definition at line 183 of file zipfl.cpp.

183  {
184  char Ch;
185  if (BfC >= BfL) { // check for eof, read more data
186  if (Eof()) { return -1; }
187  FillBf();
188  }
189  while (BfC < BfL) {
190  Ch = Bf[BfC++];
191  if (Ch=='\n') { BfN = BfC-1; return 1; }
192  if (Ch=='\r' && Bf[BfC+1]=='\n') {
193  BfC++; BfN = BfC-2; return 1; }
194  }
195  BfN = BfC;
196  return 0;
197 }
bool Eof()
Definition: zipfl.h:45
int BfL
Definition: zipfl.h:28
char * Bf
Definition: zipfl.h:27
void FillBf()
Definition: zipfl.cpp:48
int BfC
Definition: zipfl.h:28
int TZipIn::GetBf ( const void *  LBf,
const TSize LBfL 
)
virtual

Implements TSIn.

Definition at line 143 of file zipfl.cpp.

143  {
144  int LBfS=0;
145  if (TSize(BfC+LBfL)>TSize(BfL)){
146  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
147  if (BfC==BfL){FillBf();}
148  LBfS+=((char*)LBf)[LBfC]=Bf[BfC++];}
149  } else {
150  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
151  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
152  }
153  return LBfS;
154 }
int BfL
Definition: zipfl.h:28
size_t TSize
Definition: bd.h:58
char * Bf
Definition: zipfl.h:27
void FillBf()
Definition: zipfl.cpp:48
int BfC
Definition: zipfl.h:28
char TZipIn::GetCh ( )
inlinevirtual

Implements TSIn.

Definition at line 47 of file zipfl.h.

47 { if (BfC==BfL){FillBf();} return Bf[BfC++]; }
int BfL
Definition: zipfl.h:28
char * Bf
Definition: zipfl.h:27
void FillBf()
Definition: zipfl.cpp:48
int BfC
Definition: zipfl.h:28
TStr TZipIn::GetCmd ( const TStr ZipFNm)
static

Return a command-line string that is executed in order to decompress a file to standard output.

Definition at line 223 of file zipfl.cpp.

223  {
225  const TStr Ext = ZipFNm.GetFExt().GetLc();
226  EAssertR(FExtToCmdH.IsKey(Ext), TStr::Fmt("Unsupported file extension '%s'", Ext.CStr()));
227  return FExtToCmdH.GetDat(Ext);
228 }
static TStrStrH FExtToCmdH
Definition: zipfl.h:19
static void FillFExtToCmdH()
Definition: zipfl.cpp:204
bool Empty() const
Definition: hash.h:227
TStr GetFExt() const
Definition: dt.cpp:1421
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TStr GetLc() const
Definition: dt.h:502
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * CStr()
Definition: dt.h:479
bool IsKey(const TKey &Key) const
Definition: hash.h:258
uint64 TZipIn::GetCurFPos ( ) const
inline

Definition at line 53 of file zipfl.h.

53 { return CurFPos; }
uint64 CurFPos
Definition: zipfl.h:26
uint64 TZipIn::GetFLen ( ) const
inline

Definition at line 52 of file zipfl.h.

52 { return FLen; }
uint64 FLen
Definition: zipfl.h:26
uint64 TZipIn::GetFLen ( const TStr ZipFNm)
static

Return the uncompressed size (in bytes) of the compressed file ZipFNm.

Definition at line 230 of file zipfl.cpp.

230  {
231  #ifdef GLib_WIN
232  HANDLE ZipStdoutRd, ZipStdoutWr;
233  // create pipes
234  SECURITY_ATTRIBUTES saAttr;
235  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
236  saAttr.bInheritHandle = TRUE;
237  saAttr.lpSecurityDescriptor = NULL;
238  // Create a pipe for the child process's STDOUT.
239  const int PipeBufferSz = 32*1024;
240  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed");
241  // Ensure the read handle to the pipe for STDOUT is not inherited.
242  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
243  //CreateZipProcess(GetCmd(FNm), FNm);
244  { const TStr CmdLine = TStr::Fmt("7z.exe l %s", ZipFNm.CStr());
245  PROCESS_INFORMATION piProcInfo;
246  STARTUPINFO siStartInfo;
247  ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION));
248  ZeroMemory( &siStartInfo, sizeof(STARTUPINFO));
249  siStartInfo.cb = sizeof(STARTUPINFO);
250  siStartInfo.hStdOutput = ZipStdoutWr;
251  siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
252  // Create the child process.
253  const BOOL FuncRetn = CreateProcess(NULL, (LPSTR) CmdLine.CStr(),
254  NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo);
255  EAssertR(FuncRetn!=0, TStr::Fmt("Can not execute '%s' (Set the TZipIn::SevenZipPath)", CmdLine.CStr()).CStr());
256  CloseHandle(piProcInfo.hProcess);
257  CloseHandle(piProcInfo.hThread); }
258  #else
259  const TStr CmdLine = TStr::Fmt("7za l %s", ZipFNm.CStr());
260  FILE* ZipStdoutRd = popen((TZipIn::SevenZipPath+"/"+CmdLine).CStr(), "r");
261  EAssertR(ZipStdoutRd, TStr::Fmt("Can not execute '%s/%s' (Set the TZipIn::SevenZipPath)", TZipIn::SevenZipPath.CStr(), CmdLine.CStr()).CStr());
262  #endif
263  // Read output from the child process
264  const int BfSz = 32*1024;
265  char* Bf = new char [BfSz];
266  int BfC=0, BfL=0;
267  memset(Bf, 0, BfSz);
268  #ifdef GLib_WIN
269  DWORD BytesRead;
270  EAssert(ReadFile(ZipStdoutRd, Bf, MxBfL, &BytesRead, NULL) != 0);
271  #else
272  size_t BytesRead = fread(Bf, 1, MxBfL, ZipStdoutRd);
273  EAssert(BytesRead != 0);
274  EAssert(pclose(ZipStdoutRd) != -1);
275  #endif
276  BfL = (int) BytesRead; IAssert((BfC!=0)||(BfL!=0));
277  BfC = 0; Bf[BfL] = 0;
278  // find file lenght
279  TStr Str(Bf); delete [] Bf;
280  TStrV StrV; Str.SplitOnWs(StrV);
281  int n = StrV.Len()-1;
282  while (n > 0 && ! StrV[n].IsPrefix("-----")) { n--; }
283  if (n-7 <= 0) {
284  WrNotify(TStr::Fmt("Corrupt file %s: MESSAGE:\n", ZipFNm.CStr()).CStr(), Str.CStr());
285  SaveToErrLog(TStr::Fmt("Corrupt file %s. Message:\n:%s\n", ZipFNm.CStr(), Str.CStr()).CStr());
286  return 0;
287  }
288  return StrV[n-7].GetInt64();
289 }
int BfL
Definition: zipfl.h:28
#define IAssert(Cond)
Definition: bd.h:262
FILE * ZipStdoutWr
Definition: zipfl.h:24
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
static const int MxBfL
Definition: zipfl.h:20
void SaveToErrLog(const char *MsgCStr)
Definition: bd.cpp:51
char * Bf
Definition: zipfl.h:27
static TStr SevenZipPath
Definition: zipfl.h:17
FILE * ZipStdoutRd
Definition: zipfl.h:24
#define EAssert(Cond)
Definition: bd.h:280
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
int BfC
Definition: zipfl.h:28
void WrNotify(const char *CaptionCStr, const char *NotifyCStr)
Definition: bd.cpp:43
char * CStr()
Definition: dt.h:479
bool TZipIn::GetNextLnBf ( TChA LnChA)
virtual

Implements TSIn.

Definition at line 159 of file zipfl.cpp.

159  {
160  int Status;
161  int BfN; // new pointer to the end of line
162  int BfP; // previous pointer to the line start
163  LnChA.Clr();
164  do {
165  if (BfC >= BfL) { BfP = 0; } // reset the current pointer, FindEol() will read a new buffer
166  else { BfP = BfC; }
167  Status = FindEol(BfN);
168  if (Status >= 0) {
169  LnChA.AddBf(&Bf[BfP],BfN-BfP);
170  if (Status == 1) { return true; } // got a complete line
171  }
172  // get more data, if the line is incomplete
173  } while (Status == 0);
174  // eof or the last line has no newline
175  return !LnChA.Empty();
176 }
int BfL
Definition: zipfl.h:28
bool Empty() const
Definition: dt.h:260
void Clr()
Definition: dt.h:258
char * Bf
Definition: zipfl.h:27
void AddBf(char *NewBf, const int &BfS)
Definition: dt.h:275
int BfC
Definition: zipfl.h:28
int FindEol(int &BfN)
Definition: zipfl.cpp:183
bool TZipIn::IsZipExt ( const TStr FNmExt)
static

Check whether the file extension FNmExt is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).

Definition at line 199 of file zipfl.cpp.

199  {
201  return FExtToCmdH.IsKey(FNmExt);
202 }
static TStrStrH FExtToCmdH
Definition: zipfl.h:19
static void FillFExtToCmdH()
Definition: zipfl.cpp:204
bool Empty() const
Definition: hash.h:227
bool IsKey(const TKey &Key) const
Definition: hash.h:258
static bool TZipIn::IsZipFNm ( const TStr FNm)
inlinestatic

Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).

Definition at line 56 of file zipfl.h.

56 { return IsZipExt(FNm.GetFExt()); }
TStr GetFExt() const
Definition: dt.cpp:1421
static bool IsZipExt(const TStr &FNmExt)
Check whether the file extension FNmExt is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
Definition: zipfl.cpp:199
int TZipIn::Len ( ) const
inlinevirtual

Implements TSIn.

Definition at line 46 of file zipfl.h.

46 { return int(FLen-CurFPos+BfL-BfC); }
int BfL
Definition: zipfl.h:28
uint64 CurFPos
Definition: zipfl.h:26
uint64 FLen
Definition: zipfl.h:26
int BfC
Definition: zipfl.h:28
PSIn TZipIn::New ( const TStr FNm)
static

Definition at line 122 of file zipfl.cpp.

122  {
123  return PSIn(new TZipIn(FNm));
124 }
TPt< TSIn > PSIn
Definition: fl.h:119
PSIn TZipIn::New ( const TStr FNm,
bool &  OpenedP 
)
static

Definition at line 126 of file zipfl.cpp.

126  {
127  return PSIn(new TZipIn(FNm, OpenedP));
128 }
TPt< TSIn > PSIn
Definition: fl.h:119
static PSIn TZipIn::NewIfZip ( const TStr FNm)
inlinestatic

Definition at line 63 of file zipfl.h.

63 { return IsZipFNm(FNm) ? New(FNm) : TFIn::New(FNm); }
static bool IsZipFNm(const TStr &FNm)
Check whether the file extension of FNm is that of a compressed file (.gz, .7z, .rar, .zip, .cab, .arj. bzip2).
Definition: zipfl.h:56
Definition: fl.h:275
static PSIn New(const TStr &FNm)
Definition: zipfl.cpp:122
TZipIn& TZipIn::operator= ( const TZipIn )
private
char TZipIn::PeekCh ( )
inlinevirtual

Implements TSIn.

Definition at line 48 of file zipfl.h.

48 { if (BfC==BfL){FillBf();} return Bf[BfC]; }
int BfL
Definition: zipfl.h:28
char * Bf
Definition: zipfl.h:27
void FillBf()
Definition: zipfl.cpp:48
int BfC
Definition: zipfl.h:28

Member Data Documentation

char* TZipIn::Bf
private

Definition at line 27 of file zipfl.h.

int TZipIn::BfC
private

Definition at line 28 of file zipfl.h.

int TZipIn::BfL
private

Definition at line 28 of file zipfl.h.

uint64 TZipIn::CurFPos
private

Definition at line 26 of file zipfl.h.

TStrStrH TZipIn::FExtToCmdH
staticprivate

Definition at line 19 of file zipfl.h.

uint64 TZipIn::FLen
private

Definition at line 26 of file zipfl.h.

const int TZipIn::MxBfL =32*1024
staticprivate

Definition at line 20 of file zipfl.h.

TStr TZipIn::SevenZipPath = "/usr/bin"
static

Definition at line 17 of file zipfl.h.

FILE* TZipIn::ZipStdoutRd
private

Definition at line 24 of file zipfl.h.

FILE * TZipIn::ZipStdoutWr
private

Definition at line 24 of file zipfl.h.


The documentation for this class was generated from the following files: