4 #include "zipios++/zipios-config.h"
7 #include "zipios++/meta-iostreams.h"
36 updateEntryHeaderInfo() ;
37 setEntryClosedState( ) ;
50 ostream os( _outbuf ) ;
65 if ( ! init( _level ) )
66 cerr <<
"ZipOutputStreambuf::putNextEntry(): init() failed!\n" ;
68 _entries.push_back( entry ) ;
71 ostream os( _outbuf ) ;
74 ent.setLocalHeaderOffset( os.tellp() ) ;
77 os << static_cast< ZipLocalEntry >( ent ) ;
84 _zip_comment = comment ;
95 if( method == STORED )
97 else if ( method == DEFLATED ) {
98 if( _level == NO_COMPRESSION )
101 throw FCollException(
"Specified compression method not supported" ) ;
108 int ZipOutputStreambuf::overflow(
int c ) {
109 return DeflateOutputStreambuf::overflow( c ) ;
118 int ZipOutputStreambuf::sync() {
119 return DeflateOutputStreambuf::sync() ;
127 void ZipOutputStreambuf::setEntryClosedState() {
128 _open_entry = false ;
134 void ZipOutputStreambuf::updateEntryHeaderInfo() {
138 ostream os( _outbuf ) ;
139 int curr_pos = os.tellp() ;
142 ZipCDirEntry &entry = _entries.back() ;
145 entry.setCompressedSize( curr_pos - entry.getLocalHeaderOffset()
146 - entry.getLocalHeaderSize() ) ;
152 now = localtime( <ime );
153 int dosTime = (now->tm_year - 80) << 25 | (now->tm_mon + 1) << 21 | now->tm_mday << 16 |
154 now->tm_hour << 11 | now->tm_min << 5 | now->tm_sec >> 1;
155 entry.setTime(dosTime);
158 os.seekp( entry.getLocalHeaderOffset() ) ;
159 os << static_cast< ZipLocalEntry >( entry ) ;
160 os.seekp( curr_pos ) ;
164 void ZipOutputStreambuf::writeCentralDirectory(
const vector< ZipCDirEntry > &entries,
165 EndOfCentralDirectory eocd,
167 int cdir_start = os.tellp() ;
168 std::vector< ZipCDirEntry >::const_iterator it ;
171 for ( it = entries.begin() ; it != entries.end() ; ++it ) {
173 cdir_size += it->getCDirHeaderSize() ;
175 eocd.setOffset( cdir_start ) ;
176 eocd.setCDirSize( cdir_size ) ;
177 eocd.setTotalCount( entries.size() ) ;
Header file that defines ZipOutputStreambuf.
The end of the Central directory structure.
ZipOutputStreambuf(streambuf *outbuf, bool del_outbuf=false)
ZipOutputStreambuf constructor.
virtual void setMethod(StorageMethod method)
Sets the storage method field for the entry.
void setComment(const string &comment)
Sets the global comment for the Zip archive.
Specialization of ZipLocalEntry, that add fields for storing the extra information, that is only present in the entries in the zip central directory and not in the local entry headers.
DeflateOutputStreambuf is an output stream filter, that deflates the data that is written to it befor...
void closeEntry()
Closes the current entry, and positions the stream read pointer at the beginning of the next entry (i...
void close()
Calls finish.
void setMethod(StorageMethod method)
Sets the compression method to be used.
virtual ~ZipOutputStreambuf()
Destructor.
uint32 getCount() const
Returns the number of bytes written to the streambuf, that has been processed from the input buffer b...
An FCollException is used to signal a problem with a FileCollection.
void putNextEntry(const ZipCDirEntry &entry)
Begins writing the next entry.
void finish()
Closes the current entry (if one is open), then writes the Zip Central Directory Structure closing th...
uint32 getCrc32() const
Returns the CRC32 for the current stream.
void setLevel(int level)
Sets the compression level to be used for subsequent entries.