|
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) |
|
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.
TZipIn::TZipIn |
( |
const TStr & |
FNm | ) |
|
Definition at line 68 of file zipfl.cpp.
References Bf, BfC, BfL, CreateZipProcess(), TStr::CStr(), EAssertR, EFailR, TStr::Empty(), TFile::Exists(), FillBf(), FLen, TStr::Fmt(), GetCmd(), TStr::GetFExt(), GetFLen(), MxBfL, ZipStdoutRd, and ZipStdoutWr.
75 printf(
"*** Error: file %s, compression format %s not supported\n", FNm.
CStr(), FNm.
GetFExt().
CStr());
80 if (FLen == 0) {
return; }
83 SECURITY_ATTRIBUTES saAttr;
84 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
85 saAttr.bInheritHandle = TRUE;
86 saAttr.lpSecurityDescriptor = NULL;
88 const int PipeBufferSz = 32*1024;
91 SetHandleInformation(
ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
static TStr GetCmd(const TStr &ZipFNm)
Return a command-line string that is executed in order to decompress a file to standard output...
static bool Exists(const TStr &FNm)
static TStr Fmt(const char *FmtStr,...)
#define EAssertR(Cond, MsgStr)
void CreateZipProcess(const TStr &Cmd, const TStr &ZipFNm)
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.
References TStr::CStr(), EAssertR, THash< TKey, TDat, THashFunc >::Empty(), FExtToCmdH, FillFExtToCmdH(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::GetDat(), TStr::GetFExt(), TStr::GetLc(), and THash< TKey, TDat, THashFunc >::IsKey().
Referenced by TZipIn().
static TStrStrH FExtToCmdH
static void FillFExtToCmdH()
const TDat & GetDat(const TKey &Key) const
static TStr Fmt(const char *FmtStr,...)
#define EAssertR(Cond, MsgStr)
bool IsKey(const TKey &Key) const
Return the uncompressed size (in bytes) of the compressed file ZipFNm.
Definition at line 232 of file zipfl.cpp.
References Bf, BfC, BfL, TStr::CStr(), EAssert, EAssertR, TStr::Fmt(), IAssert, TVec< TVal, TSizeTy >::Len(), MxBfL, SaveToErrLog(), TStr::SplitOnWs(), WrNotify(), ZipStdoutRd, and ZipStdoutWr.
236 SECURITY_ATTRIBUTES saAttr;
237 saAttr.nLength =
sizeof(SECURITY_ATTRIBUTES);
238 saAttr.bInheritHandle = TRUE;
239 saAttr.lpSecurityDescriptor = NULL;
241 const int PipeBufferSz = 32*1024;
242 EAssertR(CreatePipe(&ZipStdoutRd, &ZipStdoutWr, &saAttr, PipeBufferSz),
"Stdout pipe creation failed");
244 SetHandleInformation(ZipStdoutRd, HANDLE_FLAG_INHERIT, 0);
247 PROCESS_INFORMATION piProcInfo;
248 STARTUPINFO siStartInfo;
249 ZeroMemory( &piProcInfo,
sizeof(PROCESS_INFORMATION));
250 ZeroMemory( &siStartInfo,
sizeof(STARTUPINFO));
251 siStartInfo.cb =
sizeof(STARTUPINFO);
253 siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
255 const BOOL FuncRetn = CreateProcess(NULL, (LPSTR) CmdLine.
CStr(),
256 NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo);
258 CloseHandle(piProcInfo.hProcess);
259 CloseHandle(piProcInfo.hThread); }
262 FILE* ZipStdoutRd = popen(CmdLine.
CStr(),
"r");
263 if (ZipStdoutRd == NULL) {
269 const int BfSz = 32*1024;
270 char*
Bf =
new char [BfSz];
275 EAssert(ReadFile(ZipStdoutRd, Bf,
MxBfL, &BytesRead, NULL) != 0);
277 size_t BytesRead = fread(Bf, 1,
MxBfL, ZipStdoutRd);
279 EAssert(pclose(ZipStdoutRd) != -1);
282 BfC = 0; Bf[
BfL] = 0;
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--; }
293 return StrV[n-7].GetInt64();
TSizeTy Len() const
Returns the number of elements in the vector.
void SaveToErrLog(const char *MsgCStr)
static TStr Fmt(const char *FmtStr,...)
#define EAssertR(Cond, MsgStr)
void WrNotify(const char *CaptionCStr, const char *NotifyCStr)
Vector is a sequence TVal objects representing an array that can change in size.
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.
References THash< TKey, TDat, THashFunc >::Empty(), FExtToCmdH, FillFExtToCmdH(), and THash< TKey, TDat, THashFunc >::IsKey().
Referenced by IsZipFNm(), and TSsParser::TSsParser().
static TStrStrH FExtToCmdH
static void FillFExtToCmdH()
bool IsKey(const TKey &Key) const
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.
References TStr::GetFExt(), and IsZipExt().
Referenced by TSnap::LoadDyNet(), TSnap::LoadDyNetGraphV(), and NewIfZip().
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).