SNAP Library 2.4, User Reference  2015-05-11 19:40:56
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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)
 
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 68 of file zipfl.cpp.

68  : TSBase(FNm.CStr()), TSIn(FNm), ZipStdoutRd(NULL), ZipStdoutWr(NULL),
69  FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
70  EAssertR(! FNm.Empty(), "Empty file-name.");
71  EAssertR(TFile::Exists(FNm), TStr::Fmt("File %s does not exist", FNm.CStr()).CStr());
72  FLen = 0;
73  // non-zip files not supported, need uncompressed file length information
74  if (FNm.GetFExt() != ".zip") {
75  printf("*** Error: file %s, compression format %s not supported\n", FNm.CStr(), FNm.GetFExt().CStr());
76  EFailR(TStr::Fmt("File %s: compression format %s not supported", FNm.CStr(), FNm.GetFExt().CStr()).CStr());
77  }
78  FLen = TZipIn::GetFLen(FNm);
79  // return for malformed files
80  if (FLen == 0) { return; } // empty file
81  #ifdef GLib_WIN
82  // create pipes
83  SECURITY_ATTRIBUTES saAttr;
84  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
85  saAttr.bInheritHandle = TRUE;
86  saAttr.lpSecurityDescriptor = NULL;
87  // Create a pipe for the child process's STDOUT.
88  const int PipeBufferSz = 32*1024;
89  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz), "Stdout pipe creation failed");
90  // Ensure the read handle to the pipe for STDOUT is not inherited.
91  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
92  #else
93  // no implementation needed
94  #endif
95  CreateZipProcess(GetCmd(FNm), FNm);
96  Bf = new char[MxBfL]; BfC = BfL=-1;
97  FillBf();
98 }
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:225
TSBase(const TSStr &Nm)
Definition: fl.h:50
static bool Exists(const TStr &FNm)
Definition: fl.cpp:941
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:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
uint64 FLen
Definition: zipfl.h:26
void FillBf()
Definition: zipfl.cpp:51
#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:476
TZipIn::TZipIn ( const TStr FNm,
bool &  OpenedP 
)

Definition at line 100 of file zipfl.cpp.

100  : TSBase(FNm.CStr()), TSIn(FNm), ZipStdoutRd(NULL), ZipStdoutWr(NULL),
101  FLen(0), CurFPos(0), Bf(NULL), BfC(0), BfL(0) {
102  EAssertR(! FNm.Empty(), "Empty file-name.");
103  FLen = TZipIn::GetFLen(FNm);
104  OpenedP = TFile::Exists(FNm);
105  if (OpenedP) {
106  #ifdef GLib_WIN
107  SECURITY_ATTRIBUTES saAttr;
108  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
109  saAttr.bInheritHandle = TRUE;
110  saAttr.lpSecurityDescriptor = NULL;
111  // Create a pipe for the child process's STDOUT.
112  EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, 0), "Stdout pipe creation failed");
113  // Ensure the read handle to the pipe for STDOUT is not inherited.
114  SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
115  #else
116  // no implementation needed
117  #endif
118  CreateZipProcess(GetCmd(FNm.GetFExt()), FNm);
119  Bf = new char[MxBfL]; BfC = BfL=-1;
120  FillBf();
121  }
122 }
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:225
TSBase(const TSStr &Nm)
Definition: fl.h:50
static bool Exists(const TStr &FNm)
Definition: fl.cpp:941
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:488
uint64 FLen
Definition: zipfl.h:26
void FillBf()
Definition: zipfl.cpp:51
#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:476
TZipIn::~TZipIn ( )

Definition at line 132 of file zipfl.cpp.

132  {
133  #ifdef GLib_WIN
134  if (ZipStdoutRd != NULL) {
135  EAssertR(CloseHandle(ZipStdoutRd), "Closing read-end of pipe failed"); }
136  if (ZipStdoutWr != NULL) {
137  EAssertR(CloseHandle(ZipStdoutWr)!=0, "Closing write-end of pipe failed"); }
138  #else
139  if (ZipStdoutRd != NULL) {
140  EAssertR(pclose(ZipStdoutRd) != -1, "Closing of the process failed"); }
141  #endif
142  if (Bf != NULL) { delete[] Bf; }
143 }
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'", CmdLine.CStr()).CStr());
40  CloseHandle(piProcInfo.hProcess);
41  CloseHandle(piProcInfo.hThread);
42  #else
43  ZipStdoutRd = popen(CmdLine.CStr(), "r");
44  if (ZipStdoutRd == 0) { // try using SevenZipPath
45  ZipStdoutRd = popen((TZipIn::SevenZipPath+"/"+CmdLine).CStr(), "r");
46  }
47  EAssertR(ZipStdoutRd != NULL, TStr::Fmt("Can not execute '%s'", CmdLine.CStr()).CStr());
48  #endif
49 }
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:476
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 51 of file zipfl.cpp.

51  {
52  EAssertR(CurFPos < FLen, "End of file "+GetSNm()+" reached.");
53  EAssertR((BfC==BfL)/*&&((BfL==-1)||(BfL==MxBfL))*/, "Error reading file '"+GetSNm()+"'.");
54  #ifdef GLib_WIN
55  // Read output from the child process
56  DWORD BytesRead;
57  EAssert(ReadFile(ZipStdoutRd, Bf, MxBfL, &BytesRead, NULL) != 0);
58  #else
59  size_t BytesRead = fread(Bf, 1, MxBfL, ZipStdoutRd);
60  EAssert(BytesRead != 0);
61  #endif
62  BfL = (int) BytesRead;
63  CurFPos += BytesRead;
64  EAssertR((BfC!=0)||(BfL!=0), "Error reading file '"+GetSNm()+"'.");
65  BfC = 0;
66 }
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
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
void TZipIn::FillFExtToCmdH ( )
staticprivate

Definition at line 206 of file zipfl.cpp.

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

Definition at line 185 of file zipfl.cpp.

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

Implements TSIn.

Definition at line 145 of file zipfl.cpp.

145  {
146  int LBfS=0;
147  if (TSize(BfC+LBfL)>TSize(BfL)){
148  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
149  if (BfC==BfL){FillBf();}
150  LBfS+=((char*)LBf)[LBfC]=Bf[BfC++];}
151  } else {
152  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
153  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
154  }
155  return LBfS;
156 }
int BfL
Definition: zipfl.h:28
size_t TSize
Definition: bd.h:58
char * Bf
Definition: zipfl.h:27
void FillBf()
Definition: zipfl.cpp:51
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:51
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 225 of file zipfl.cpp.

225  {
227  const TStr Ext = ZipFNm.GetFExt().GetLc();
228  EAssertR(FExtToCmdH.IsKey(Ext), TStr::Fmt("Unsupported file extension '%s'", Ext.CStr()));
229  return FExtToCmdH.GetDat(Ext);
230 }
static TStrStrH FExtToCmdH
Definition: zipfl.h:19
static void FillFExtToCmdH()
Definition: zipfl.cpp:206
bool Empty() const
Definition: hash.h:185
TStr GetFExt() const
Definition: dt.cpp:1421
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TStr GetLc() const
Definition: dt.h:499
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:476
bool IsKey(const TKey &Key) const
Definition: hash.h:216
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 232 of file zipfl.cpp.

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

Implements TSIn.

Definition at line 161 of file zipfl.cpp.

161  {
162  int Status;
163  int BfN; // new pointer to the end of line
164  int BfP; // previous pointer to the line start
165  LnChA.Clr();
166  do {
167  if (BfC >= BfL) { BfP = 0; } // reset the current pointer, FindEol() will read a new buffer
168  else { BfP = BfC; }
169  Status = FindEol(BfN);
170  if (Status >= 0) {
171  LnChA.AddBf(&Bf[BfP],BfN-BfP);
172  if (Status == 1) { return true; } // got a complete line
173  }
174  // get more data, if the line is incomplete
175  } while (Status == 0);
176  // eof or the last line has no newline
177  return !LnChA.Empty();
178 }
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:185
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 201 of file zipfl.cpp.

201  {
203  return FExtToCmdH.IsKey(FNmExt);
204 }
static TStrStrH FExtToCmdH
Definition: zipfl.h:19
static void FillFExtToCmdH()
Definition: zipfl.cpp:206
bool Empty() const
Definition: hash.h:185
bool IsKey(const TKey &Key) const
Definition: hash.h:216
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:201
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 124 of file zipfl.cpp.

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

Definition at line 128 of file zipfl.cpp.

128  {
129  return PSIn(new TZipIn(FNm, OpenedP));
130 }
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:124
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:51
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: