Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cheprep::ZipOutputStreamBuffer Class Reference

#include <ZipOutputStreamBuffer.h>

Inheritance diagram for cheprep::ZipOutputStreamBuffer:
Collaboration 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 19 of file ZipOutputStreamBuffer.h.

Constructor & Destructor Documentation

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

Definition at line 17 of file ZipOutputStreamBuffer.cc.

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

Definition at line 140 of file ZipOutputStreamBuffer.cc.

140  {
141  close();
142  }

Here is the call graph for this function:

Member Function Documentation

void cheprep::ZipOutputStreamBuffer::close ( )

Definition at line 49 of file ZipOutputStreamBuffer.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void cheprep::ZipOutputStreamBuffer::closeEntry ( )

Definition at line 31 of file ZipOutputStreamBuffer.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 27 of file ZipOutputStreamBuffer.cc.

Here is the call graph for this function:

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

Definition at line 96 of file ZipOutputStreamBuffer.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 135 of file ZipOutputStreamBuffer.cc.

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

Here is the caller graph for this function:

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

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