2
#include "zipios++/zipios-config.h"
5
#include "zipios++/meta-iostreams.h"
9
#include "zipios++/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.
52
if ( _curr_entry.isValid() ) {
53
_data_start = _inbuf->pubseekoff(0, ios::cur,
55
if ( _curr_entry.getMethod() == DEFLATED ) {
57
reset() ; // reset inflatestream data structures
58
// cerr << "deflated" << endl ;
59
} else if ( _curr_entry.getMethod() == STORED ) {
61
_remain = _curr_entry.getSize() ;
62
// Force underflow on first read:
63
setg( &( _outvec[ 0 ] ),
64
&( _outvec[ 0 ] ) + _outvecsize,
65
&( _outvec[ 0 ] ) + _outvecsize ) ;
66
// cerr << "stored" << endl ;
68
_open_entry = false ; // Unsupported compression format.
69
throw FCollException( "Unsupported compression format" ) ;
75
if ( _curr_entry.isValid() && _curr_entry.trailingDataDescriptor() )
76
throw FCollException( "Trailing data descriptor in zip file not supported" ) ;
77
return new ZipLocalEntry( _curr_entry ) ;
81
ZipInputStreambuf::~ZipInputStreambuf() {
85
int ZipInputStreambuf::underflow() {
87
return EOF ; // traits_type::eof()
88
if ( _curr_entry.getMethod() == DEFLATED )
89
return InflateInputStreambuf::underflow() ;
91
// Ok, we're are stored, so we handle it ourselves.
92
int num_b = min( _remain, _outvecsize ) ;
93
int g = _inbuf->sgetn( &(_outvec[ 0 ] ) , num_b ) ;
94
setg( &( _outvec[ 0 ] ),
96
&( _outvec[ 0 ] ) + g ) ;
99
return static_cast< unsigned char >( *gptr() ) ;
101
return EOF ; // traits_type::eof()
105
// FIXME: We need to check somew
107
// // gp_bitfield bit 3 is one, if the length of the zip entry
108
// // is stored in a trailer.
109
// if ( is->good && ( _curr_entry.gp_bitfield & 4 ) != 1 )
120
Implementation of ZipInputStreambuf.
124
Zipios++ - a small C++ library that provides easy access to .zip files.
125
Copyright (C) 2000 Thomas S�ndergaard
127
This library is free software; you can redistribute it and/or
128
modify it under the terms of the GNU Lesser General Public
129
License as published by the Free Software Foundation; either
130
version 2 of the License, or (at your option) any later version.
132
This library is distributed in the hope that it will be useful,
133
but WITHOUT ANY WARRANTY; without even the implied warranty of
134
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
135
Lesser General Public License for more details.
137
You should have received a copy of the GNU Lesser General Public
138
License along with this library; if not, write to the Free Software
139
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA