Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
cheprep::ZipOutputStreamBuffer Class Reference

#include <ZipOutputStreamBuffer.h>

+ Inheritance diagram for cheprep::ZipOutputStreamBuffer:

Public Member Functions

 ZipOutputStreamBuffer (std::streambuf *buffer)
 
int overflow (int c)
 
void closeEntry ()
 
void close ()
 
void putNextEntry (const std::string &name, bool compress)
 
void setMethod (int method)
 
void setComment (const std::string &comment)
 
virtual ~ZipOutputStreamBuffer ()
 
- Public Member Functions inherited from cheprep::DeflateOutputStreamBuffer
 DeflateOutputStreamBuffer (std::streambuf *buffer)
 
void init (bool compress)
 
void finish ()
 
virtual ~DeflateOutputStreamBuffer ()
 

Additional Inherited Members

- Protected Member Functions inherited from cheprep::DeflateOutputStreamBuffer
int overflow (int c=EOF)
 
bool flushOut ()
 
void putUI (unsigned int ui)
 
void putUS (unsigned short us)
 
void putUB (unsigned char ub)
 
void putS (const std::string s)
 
std::streampos pos ()
 
unsigned int getSize ()
 
unsigned int getCRC ()
 

Detailed Description

Definition at line 18 of file ZipOutputStreamBuffer.h.

Constructor & Destructor Documentation

◆ ZipOutputStreamBuffer()

cheprep::ZipOutputStreamBuffer::ZipOutputStreamBuffer ( std::streambuf *  buffer)

Definition at line 16 of file ZipOutputStreamBuffer.cc.

17 : DeflateOutputStreamBuffer(aBuffer),
18 comment("") {
19
20 closed = false;
21 entry = NULL;
22
23 entries = new std::vector<ZipEntry*>();
24 }

◆ ~ZipOutputStreamBuffer()

cheprep::ZipOutputStreamBuffer::~ZipOutputStreamBuffer ( )
virtual

Definition at line 139 of file ZipOutputStreamBuffer.cc.

139 {
140 close();
141 }

Member Function Documentation

◆ close()

void cheprep::ZipOutputStreamBuffer::close ( )

Definition at line 48 of file ZipOutputStreamBuffer.cc.

48 {
49 if (closed) return;
50 closeEntry();
51
52 long dirStart = pos();
53 for (std::vector<ZipEntry*>::iterator i=entries->begin(); i != entries->end(); i++) {
54 entry = *i;
55 putUI(CENSIG);
56 putUS(VERSIONMADE); // made by version
57 putUS(VERSIONEXTRACT); // extraction version
58 putUS(GENFLAG); // general purpose bit flag
59 putUS(entry->method); // compression method
60 putUS(entry->time); // time
61 putUS(entry->date); // date
62 putUI(entry->crc); // crc
63 putUI(entry->csize); // compressed size
64 putUI(entry->size); // uncompressed size
65 putUS(entry->name.length()); // file name length
66 putUS(0); // extra field length
67 putUS(0); // file comment length
68 putUS(0); // disk number start
69 putUS(0); // internal file attributes
70 putUI(0); // external file attributes
71 putUI(entry->offset); // relative offset of local file header
72 putS(entry->name); // file name
73
74 // delete entry
75 delete entry;
76 entry = NULL;
77 }
78 // NOTE: pos()::operator- is ambiguous on gcc 4.0, so convert to long first
79 long dirSize = (long)pos() - dirStart;
80 putUI(ENDSIG);
81 putUS(0); // number of this disk
82 putUS(0); // number of the disk with the start of central directory
83 putUS(entries->size()); // total number of entries in the central directory of this disk
84 putUS(entries->size()); // total number of entries in the central directory
85 putUI(dirSize); // size of the central directory
86 putUI(dirStart); // offset of the start of central directory with respect to the starting disk number
87 putUS(comment.length()); // .ZIP file comment length
88 putS(comment); // .ZIP file comment
89
90 delete entries;
91 entries = NULL;
92 closed = true;
93 }
std::string name
Definition: ZipEntry.h:17
unsigned int csize
Definition: ZipEntry.h:23
unsigned int size
Definition: ZipEntry.h:22
unsigned int crc
Definition: ZipEntry.h:21

Referenced by cheprep::ZipOutputStream::close(), and ~ZipOutputStreamBuffer().

◆ closeEntry()

void cheprep::ZipOutputStreamBuffer::closeEntry ( )

Definition at line 30 of file ZipOutputStreamBuffer.cc.

30 {
31 if (closed) return;
32 if (entry == NULL) return;
33
34 finish();
35
36 entry->crc = getCRC();
37 // NOTE: pos()::operator- is ambiguous on gcc 4.0, so convert to long first
38 entry->csize = (long)pos() - entry->data;
39 entry->size = getSize();
40 putUI(EXTSIG);
41 putUI(entry->crc); // crc
42 putUI(entry->csize); // compressed size
43 putUI(entry->size); // uncompressed size
44 entry = NULL;
45 }

Referenced by close(), cheprep::ZipOutputStream::closeEntry(), and putNextEntry().

◆ overflow()

int cheprep::ZipOutputStreamBuffer::overflow ( int  c)

Definition at line 26 of file ZipOutputStreamBuffer.cc.

◆ putNextEntry()

void cheprep::ZipOutputStreamBuffer::putNextEntry ( const std::string &  name,
bool  compress 
)

Definition at line 95 of file ZipOutputStreamBuffer.cc.

95 {
96 if (closed) return;
97
98 closeEntry();
99
100#ifdef CHEPREP_NO_ZLIB
101 compress = false;
102#endif
103 init(compress);
104
105 entry = new ZipEntry();
106 entries->push_back(entry);
107
108 entry->name = name;
109 entry->method = compress ? 8 : 0;
110
111 time_t ltime;
112 time( &ltime );
113 struct tm *utc = gmtime( &ltime );
114 entry->date = (utc->tm_year - 80) << 9 | (utc->tm_mon + 1) << 5 | utc->tm_mday;
115 entry->time = utc->tm_hour << 11 | utc->tm_min << 5 | utc->tm_sec >> 1;
116
117 entry->offset = (long)pos();
118 putUI(LOCSIG); // signature
119 putUS(VERSIONEXTRACT); // extraction version
120 putUS(GENFLAG); // general purpose bit flag
121 putUS(entry->method); // compression method
122 putUS(entry->time); // time
123 putUS(entry->date); // date
124 putUI(0x00000000); // crc ATEND
125 putUI(0x00000000); // compressed size ATEND
126 putUI(0x00000000); // uncompressed size ATEND
127 putUS(entry->name.length()); // file name length
128 putUS(0); // extra field length
129 putS(entry->name); // file name
130 entry->data = (long)pos();
131 entry->crc = 0;
132 }
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:67
const char * name(G4int ptype)

Referenced by cheprep::ZipOutputStream::putNextEntry().

◆ setComment()

void cheprep::ZipOutputStreamBuffer::setComment ( const std::string &  comment)

Definition at line 134 of file ZipOutputStreamBuffer.cc.

134 {
135 if (closed) return;
136 comment = c;
137 }

Referenced by cheprep::ZipOutputStream::setComment().

◆ setMethod()

void cheprep::ZipOutputStreamBuffer::setMethod ( int  method)

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