|
SNAP Library 2.1, User Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <zipfl.h>
Inherits TSOut.
Public Member Functions | |
| TZipOut (const TStr &_FNm) | |
| ~TZipOut () | |
| int | PutCh (const char &Ch) |
| int | PutBf (const void *LBf, const TSize &LBfL) |
| void | Flush () |
Static Public Member Functions | |
| static PSOut | New (const TStr &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). | |
| 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). | |
| static TStr | GetCmd (const TStr &ZipFNm) |
| Return a command-line string that is executed in order to decompress a file to standard output. | |
| static PSOut | NewIfZip (const TStr &FNm) |
Private Member Functions | |
| void | FlushBf () |
| void | CreateZipProcess (const TStr &Cmd, const TStr &ZipFNm) |
| TZipOut () | |
| TZipOut (const TZipOut &) | |
| TZipOut & | operator= (const TZipOut &) |
Static Private Member Functions | |
| static void | FillFExtToCmdH () |
Private Attributes | |
| FILE * | ZipStdinRd |
| FILE * | ZipStdinWr |
| char * | Bf |
| TSize | BfL |
Static Private Attributes | |
| static const TSize | MxBfL = 4*1024 |
| static TStrStrH | FExtToCmdH |
Compressed File Output Stream. The class directly writes to a compressed file. This is eachieved by TZipFl outputing into a pipe from which 7ZIP then reads and compresses. 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 TZIpOut expects that '7z' ('7z.exe') is in the working path. Note2: For 7z to work properly you need both the 7z executable and the directory 'Codecs'. Note3: Use TZipIn::SevenZipPath to set the path to 7z executable.
| TZipOut::TZipOut | ( | ) | [private] |
| TZipOut::TZipOut | ( | const TZipOut & | ) | [private] |
| TZipOut::TZipOut | ( | const TStr & | _FNm | ) |
Definition at line 338 of file zipfl.cpp.
: TSBase(FNm.CStr()), TSOut(FNm), ZipStdinRd(NULL), ZipStdinWr(NULL), Bf(NULL), BfL(0){ EAssertR(! FNm.Empty(), "Empty file-name."); #ifdef GLib_WIN // create pipes SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; // Create a pipe for the child process's STDOUT. EAssertR(CreatePipe(&ZipStdinRd, &ZipStdinWr, &saAttr, 0), "Stdout pipe creation failed"); // Ensure the read handle to the pipe for STDOUT is not inherited. SetHandleInformation(ZipStdinWr, HANDLE_FLAG_INHERIT, 0); #else // no implementation necessary #endif CreateZipProcess(GetCmd(FNm), FNm); Bf=new char[MxBfL]; BfL=0; }
Definition at line 361 of file zipfl.cpp.
{
if (BfL!=0) { FlushBf(); }
#ifdef GLib_WIN
if (ZipStdinWr != NULL) { EAssertR(CloseHandle(ZipStdinWr), "Closing write-end of pipe failed"); }
if (ZipStdinRd != NULL) { EAssertR(CloseHandle(ZipStdinRd), "Closing read-end of pipe failed"); }
#else
if (ZipStdinWr != NULL) { EAssertR(pclose(ZipStdinWr) != -1, "Closing of the process failed"); }
#endif
if (Bf!=NULL) { delete[] Bf; }
}
| void TZipOut::CreateZipProcess | ( | const TStr & | Cmd, |
| const TStr & | ZipFNm | ||
| ) | [private] |
Definition at line 305 of file zipfl.cpp.
{
const TStr CmdLine = TStr::Fmt("%s %s", Cmd.CStr(), ZipFNm.CStr());
#ifdef GLib_WIN
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO));
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.hStdInput = ZipStdinRd;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
// Create the child process.
const BOOL FuncRetn = CreateProcess(NULL,
(LPSTR) CmdLine.CStr(), // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
EAssertR(FuncRetn!=0, TStr::Fmt("Can not execute '%s'", CmdLine.CStr()).CStr());
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
#else
ZipStdinWr = popen(CmdLine.CStr(),"w");
if (ZipStdinWr == NULL) { // try using SevenZipPath
ZipStdinWr = popen((TZipIn::SevenZipPath+"/"+CmdLine).CStr(), "r");
}
EAssertR(ZipStdinWr != NULL, TStr::Fmt("Can not execute '%s'", CmdLine.CStr()).CStr());
#endif
}
| void TZipOut::FillFExtToCmdH | ( | ) | [static, private] |
Definition at line 403 of file zipfl.cpp.
{
// 7za compress: "a -y -bd -si{CompressedFNm}"
#ifdef GLib_WIN
const char* ZipCmd = "7z.exe a -y -bd -si";
#else
const char* ZipCmd = "7za a -y -bd -si";
#endif
if (FExtToCmdH.Empty()) {
FExtToCmdH.AddDat(".gz", ZipCmd);
FExtToCmdH.AddDat(".7z", ZipCmd);
FExtToCmdH.AddDat(".rar", ZipCmd);
FExtToCmdH.AddDat(".zip", ZipCmd);
FExtToCmdH.AddDat(".cab", ZipCmd);
FExtToCmdH.AddDat(".arj", ZipCmd);
FExtToCmdH.AddDat(".bzip2", ZipCmd);
FExtToCmdH.AddDat(".bz2", ZipCmd);
}
}
| void TZipOut::Flush | ( | ) | [virtual] |
Implements TSOut.
Definition at line 389 of file zipfl.cpp.
{
FlushBf();
#ifdef GLib_WIN
EAssertR(FlushFileBuffers(ZipStdinWr)!=0, "Can not flush file '"+GetSNm()+"'.");
#else
EAssertR(fflush(ZipStdinWr)==0, "Can not flush file '"+GetSNm()+"'.");
#endif
}
| void TZipOut::FlushBf | ( | ) | [private] |
| TStr TZipOut::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 422 of file zipfl.cpp.
{
if (FExtToCmdH.Empty()) FillFExtToCmdH();
const TStr Ext = ZipFNm.GetFExt().GetLc();
EAssertR(FExtToCmdH.IsKey(Ext), TStr::Fmt("Unsupported file extension '%s'", Ext.CStr()));
return FExtToCmdH.GetDat(Ext)+ZipFNm.GetFMid();
}
| bool TZipOut::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 398 of file zipfl.cpp.
{
if (FExtToCmdH.Empty()) FillFExtToCmdH();
return FExtToCmdH.IsKey(FNmExt);
}
| static bool TZipOut::IsZipFNm | ( | const TStr & | FNm | ) | [inline, static] |
| PSOut TZipOut::New | ( | const TStr & | FNm | ) | [static] |
| static PSOut TZipOut::NewIfZip | ( | const TStr & | FNm | ) | [inline, static] |
| int TZipOut::PutBf | ( | const void * | LBf, |
| const TSize & | LBfL | ||
| ) | [virtual] |
| int TZipOut::PutCh | ( | const char & | Ch | ) | [virtual] |
char* TZipOut::Bf [private] |
TSize TZipOut::BfL [private] |
TStrStrH TZipOut::FExtToCmdH [static, private] |
const TSize TZipOut::MxBfL = 4*1024 [static, private] |
FILE* TZipOut::ZipStdinRd [private] |
FILE * TZipOut::ZipStdinWr [private] |