2 #include "zipios++/zipios-config.h"
4 #include "zipios++/meta-iostreams.h"
8 #include "zipios_common.h"
9 #include "zipios++/zipheadio.h"
11 #include "outputstringstream.h"
15 std::istream& operator>> ( std::istream &is, ZipLocalEntry &zlh ) {
16 zlh._valid = false ; // set to true upon successful completion.
20 // // Before reading anything we record the position in the stream
21 // // This is a field in the central directory entry, but not
22 // // in the local entry. After all, we know where we are, anyway.
23 // zlh.rel_offset_loc_head = is.tellg() ;
25 if ( zlh.signature != readUint32( is ) ) {
26 // put stream in error state and return
27 is.setstate ( std::ios::failbit ) ;
31 zlh.extract_version = readUint16( is ) ;
32 zlh.gp_bitfield = readUint16( is ) ;
33 zlh.compress_method = readUint16( is ) ;
34 zlh.last_mod_ftime = readUint16( is ) ;
35 zlh.last_mod_fdate = readUint16( is ) ;
36 zlh.crc_32 = readUint32( is ) ;
37 zlh.compress_size = readUint32( is ) ;
38 zlh.uncompress_size = readUint32( is ) ;
39 zlh.filename_len = readUint16( is ) ;
40 zlh.extra_field_len = readUint16( is ) ;
42 // Read filename and extra_field
43 readByteSeq( is, zlh.filename, zlh.filename_len ) ;
44 readByteSeq( is, zlh.extra_field, zlh.extra_field_len ) ;
52 std::istream& operator>> ( std::istream &is, DataDescriptor & ) {
57 std::istream& operator>> ( std::istream &is, ZipCDirEntry &zcdh ) {
58 zcdh._valid = false ; // set to true upon successful completion.
62 if ( zcdh.signature != readUint32( is ) ) {
63 // put stream in error state and return
64 is.setstate ( std::ios::failbit ) ;
68 zcdh.writer_version = readUint16( is ) ;
69 zcdh.extract_version = readUint16( is ) ;
70 zcdh.gp_bitfield = readUint16( is ) ;
71 zcdh.compress_method = readUint16( is ) ;
72 zcdh.last_mod_ftime = readUint16( is ) ;
73 zcdh.last_mod_fdate = readUint16( is ) ;
74 zcdh.crc_32 = readUint32( is ) ;
75 zcdh.compress_size = readUint32( is ) ;
76 zcdh.uncompress_size = readUint32( is ) ;
77 zcdh.filename_len = readUint16( is ) ;
78 zcdh.extra_field_len = readUint16( is ) ;
79 zcdh.file_comment_len = readUint16( is ) ;
80 zcdh.disk_num_start = readUint16( is ) ;
81 zcdh.intern_file_attr = readUint16( is ) ;
82 zcdh.extern_file_attr = readUint32( is ) ;
83 zcdh.rel_offset_loc_head = readUint32( is ) ;
85 // Read filename and extra_field
86 readByteSeq( is, zcdh.filename, zcdh.filename_len ) ;
87 readByteSeq( is, zcdh.extra_field, zcdh.extra_field_len ) ;
88 readByteSeq( is, zcdh.file_comment, zcdh.file_comment_len ) ;
95 std::ostream &operator<< ( std::ostream &os, const ZipLocalEntry &zlh ) {
99 writeUint32( zlh.signature , os ) ;
100 writeUint16( zlh.extract_version, os ) ;
101 writeUint16( zlh.gp_bitfield , os ) ;
102 writeUint16( zlh.compress_method, os ) ;
103 writeUint16( zlh.last_mod_ftime , os ) ;
104 writeUint16( zlh.last_mod_fdate , os ) ;
105 writeUint32( zlh.crc_32 , os ) ;
106 writeUint32( zlh.compress_size , os ) ;
107 writeUint32( zlh.uncompress_size, os ) ;
108 writeUint16( zlh.filename_len , os ) ;
109 writeUint16( zlh.extra_field_len, os ) ;
112 // Write filename and extra_field
113 writeByteSeq( os, zlh.filename ) ;
114 writeByteSeq( os, zlh.extra_field ) ;
119 std::ostream &operator<< ( std::ostream &os, const ZipCDirEntry &zcdh ) {
123 writeUint32( zcdh.signature , os ) ;
124 writeUint16( zcdh.writer_version , os ) ;
125 writeUint16( zcdh.extract_version , os ) ;
126 writeUint16( zcdh.gp_bitfield , os ) ;
127 writeUint16( zcdh.compress_method , os ) ;
128 writeUint16( zcdh.last_mod_ftime , os ) ;
129 writeUint16( zcdh.last_mod_fdate , os ) ;
130 writeUint32( zcdh.crc_32 , os ) ;
131 writeUint32( zcdh.compress_size , os ) ;
132 writeUint32( zcdh.uncompress_size , os ) ;
133 writeUint16( zcdh.filename_len , os ) ;
134 writeUint16( zcdh.extra_field_len , os ) ;
135 writeUint16( zcdh.file_comment_len , os ) ;
136 writeUint16( zcdh.disk_num_start , os ) ;
137 writeUint16( zcdh.intern_file_attr , os ) ;
138 writeUint32( zcdh.extern_file_attr , os ) ;
139 writeUint32( zcdh.rel_offset_loc_head, os ) ;
141 // Write filename and extra_field
142 writeByteSeq( os, zcdh.filename ) ;
143 writeByteSeq( os, zcdh.extra_field ) ;
144 writeByteSeq( os, zcdh.file_comment ) ;
149 std::ostream &operator<< ( std::ostream &os, const EndOfCentralDirectory &eocd ) {
153 writeUint32( eocd.signature , os ) ;
154 writeUint16( eocd.disk_num , os ) ;
155 writeUint16( eocd.cdir_disk_num , os ) ;
156 writeUint16( eocd.cdir_entries , os ) ;
157 writeUint16( eocd.cdir_tot_entries, os ) ;
158 writeUint32( eocd.cdir_size , os ) ;
159 writeUint32( eocd.cdir_offset , os ) ;
160 writeUint16( eocd.zip_comment_len , os ) ;
162 writeByteSeq( os, eocd.zip_comment ) ;
174 Implementation of I/O functions for the header structures
175 defined in ziphead.h.
179 Zipios++ - a small C++ library that provides easy access to .zip files.
180 Copyright (C) 2000 Thomas Søndergaard
182 This library is free software; you can redistribute it and/or
183 modify it under the terms of the GNU Lesser General Public
184 License as published by the Free Software Foundation; either
185 version 2 of the License, or (at your option) any later version.
187 This library is distributed in the hope that it will be useful,
188 but WITHOUT ANY WARRANTY; without even the implied warranty of
189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
190 Lesser General Public License for more details.
192 You should have received a copy of the GNU Lesser General Public
193 License along with this library; if not, write to the Free Software
194 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA