2
#include "zipios-config.h"
5
#include "meta-iostreams.h"
9
#include "zipinputstreambuf.h"
10
#include "zipios_common.h"
18
ZipInputStreambuf::ZipInputStreambuf( streambuf *inbuf, int s_pos, bool del_inbuf )
19
: InflateInputStreambuf( inbuf, s_pos, del_inbuf ),
22
ConstEntryPointer entry = getNextEntry() ;
24
if ( ! entry->isValid() ) {
25
; // FIXME: throw something?
29
void ZipInputStreambuf::closeEntry() {
33
// check if we're positioned correctly, otherwise position us correctly
34
int position = _inbuf->pubseekoff(0, ios::cur,
36
if ( position != _data_start + static_cast< int >( _curr_entry.getCompressedSize() ) )
37
_inbuf->pubseekoff(_data_start + _curr_entry.getCompressedSize(),
42
void ZipInputStreambuf::close() {
45
ConstEntryPointer ZipInputStreambuf::getNextEntry() {
49
// read the zip local header
50
istream is( _inbuf ) ; // istream does not destroy the streambuf.
51
is.exceptions(istream::eofbit | istream::failbit | istream::badbit);
53
if ( _curr_entry.isValid() ) {
54
_data_start = _inbuf->pubseekoff(0, ios::cur,
56
if ( _curr_entry.getMethod() == DEFLATED ) {
58
reset() ; // reset inflatestream data structures
59
// cerr << "deflated" << endl ;
60
} else if ( _curr_entry.getMethod() == STORED ) {
62
_remain = _curr_entry.getSize() ;
63
// Force underflow on first read:
64
setg( &( _outvec[ 0 ] ),
65
&( _outvec[ 0 ] ) + _outvecsize,
66
&( _outvec[ 0 ] ) + _outvecsize ) ;
67
// cerr << "stored" << endl ;
69
_open_entry = false ; // Unsupported compression format.
70
throw FCollException( "Unsupported compression format" ) ;
76
if ( _curr_entry.isValid() && _curr_entry.trailingDataDescriptor() )
77
throw FCollException( "Trailing data descriptor in zip file not supported" ) ;
78
return new ZipLocalEntry( _curr_entry ) ;
82
ZipInputStreambuf::~ZipInputStreambuf() {
86
int ZipInputStreambuf::underflow() {
88
return EOF ; // traits_type::eof()
89
if ( _curr_entry.getMethod() == DEFLATED )
90
return InflateInputStreambuf::underflow() ;
92
// Ok, we're are stored, so we handle it ourselves.
93
int num_b = min( _remain, _outvecsize ) ;
94
int g = _inbuf->sgetn( &(_outvec[ 0 ] ) , num_b ) ;
95
setg( &( _outvec[ 0 ] ),
97
&( _outvec[ 0 ] ) + g ) ;
100
return static_cast< unsigned char >( *gptr() ) ;
102
return EOF ; // traits_type::eof()
106
// FIXME: We need to check somew
108
// // gp_bitfield bit 3 is one, if the length of the zip entry
109
// // is stored in a trailer.
110
// if ( is->good && ( _curr_entry.gp_bitfield & 4 ) != 1 )
121
Implementation of ZipInputStreambuf.
125
Zipios++ - a small C++ library that provides easy access to .zip files.
126
Copyright (C) 2000 Thomas Søndergaard
128
This library is free software; you can redistribute it and/or
129
modify it under the terms of the GNU Lesser General Public
130
License as published by the Free Software Foundation; either
131
version 2 of the License, or (at your option) any later version.
133
This library is distributed in the hope that it will be useful,
134
but WITHOUT ANY WARRANTY; without even the implied warranty of
135
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
136
Lesser General Public License for more details.
138
You should have received a copy of the GNU Lesser General Public
139
License along with this library; if not, write to the Free Software
140
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA