Zipios++
|
00001 00002 #include "zipios++/zipios-config.h" 00003 00004 #include "zipios++/meta-iostreams.h" 00005 #include <iterator> 00006 #include <string> 00007 00008 #include "zipios_common.h" 00009 #include "zipios++/zipheadio.h" 00010 00011 #include "outputstringstream.h" 00012 00013 namespace zipios { 00014 00015 std::istream& operator>> ( std::istream &is, ZipLocalEntry &zlh ) { 00016 zlh._valid = false ; // set to true upon successful completion. 00017 if ( ! is ) 00018 return is ; 00019 00020 // // Before reading anything we record the position in the stream 00021 // // This is a field in the central directory entry, but not 00022 // // in the local entry. After all, we know where we are, anyway. 00023 // zlh.rel_offset_loc_head = is.tellg() ; 00024 00025 if ( zlh.signature != readUint32( is ) ) { 00026 // put stream in error state and return 00027 is.setstate ( std::ios::failbit ) ; 00028 return is ; 00029 } 00030 00031 zlh.extract_version = readUint16( is ) ; 00032 zlh.gp_bitfield = readUint16( is ) ; 00033 zlh.compress_method = readUint16( is ) ; 00034 zlh.last_mod_ftime = readUint16( is ) ; 00035 zlh.last_mod_fdate = readUint16( is ) ; 00036 zlh.crc_32 = readUint32( is ) ; 00037 zlh.compress_size = readUint32( is ) ; 00038 zlh.uncompress_size = readUint32( is ) ; 00039 zlh.filename_len = readUint16( is ) ; 00040 zlh.extra_field_len = readUint16( is ) ; 00041 00042 // Read filename and extra_field 00043 readByteSeq( is, zlh.filename, zlh.filename_len ) ; 00044 readByteSeq( is, zlh.extra_field, zlh.extra_field_len ) ; 00045 00046 if ( is ) 00047 zlh._valid = true ; 00048 return is ; 00049 } 00050 00051 00052 std::istream& operator>> ( std::istream &is, DataDescriptor & ) { 00053 return is ; 00054 } 00055 00056 00057 std::istream& operator>> ( std::istream &is, ZipCDirEntry &zcdh ) { 00058 zcdh._valid = false ; // set to true upon successful completion. 00059 if ( ! is ) 00060 return is ; 00061 00062 if ( zcdh.signature != readUint32( is ) ) { 00063 // put stream in error state and return 00064 is.setstate ( std::ios::failbit ) ; 00065 return is ; 00066 } 00067 00068 zcdh.writer_version = readUint16( is ) ; 00069 zcdh.extract_version = readUint16( is ) ; 00070 zcdh.gp_bitfield = readUint16( is ) ; 00071 zcdh.compress_method = readUint16( is ) ; 00072 zcdh.last_mod_ftime = readUint16( is ) ; 00073 zcdh.last_mod_fdate = readUint16( is ) ; 00074 zcdh.crc_32 = readUint32( is ) ; 00075 zcdh.compress_size = readUint32( is ) ; 00076 zcdh.uncompress_size = readUint32( is ) ; 00077 zcdh.filename_len = readUint16( is ) ; 00078 zcdh.extra_field_len = readUint16( is ) ; 00079 zcdh.file_comment_len = readUint16( is ) ; 00080 zcdh.disk_num_start = readUint16( is ) ; 00081 zcdh.intern_file_attr = readUint16( is ) ; 00082 zcdh.extern_file_attr = readUint32( is ) ; 00083 zcdh.rel_offset_loc_head = readUint32( is ) ; 00084 00085 // Read filename and extra_field 00086 readByteSeq( is, zcdh.filename, zcdh.filename_len ) ; 00087 readByteSeq( is, zcdh.extra_field, zcdh.extra_field_len ) ; 00088 readByteSeq( is, zcdh.file_comment, zcdh.file_comment_len ) ; 00089 00090 if ( is ) 00091 zcdh._valid = true ; 00092 return is ; 00093 } 00094 00095 std::ostream &operator<< ( std::ostream &os, const ZipLocalEntry &zlh ) { 00096 if ( ! os ) 00097 return os ; 00098 00099 writeUint32( zlh.signature , os ) ; 00100 writeUint16( zlh.extract_version, os ) ; 00101 writeUint16( zlh.gp_bitfield , os ) ; 00102 writeUint16( zlh.compress_method, os ) ; 00103 writeUint16( zlh.last_mod_ftime , os ) ; 00104 writeUint16( zlh.last_mod_fdate , os ) ; 00105 writeUint32( zlh.crc_32 , os ) ; 00106 writeUint32( zlh.compress_size , os ) ; 00107 writeUint32( zlh.uncompress_size, os ) ; 00108 writeUint16( zlh.filename_len , os ) ; 00109 writeUint16( zlh.extra_field_len, os ) ; 00110 00111 00112 // Write filename and extra_field 00113 writeByteSeq( os, zlh.filename ) ; 00114 writeByteSeq( os, zlh.extra_field ) ; 00115 00116 return os ; 00117 } 00118 00119 std::ostream &operator<< ( std::ostream &os, const ZipCDirEntry &zcdh ) { 00120 if ( ! os ) 00121 return os ; 00122 00123 writeUint32( zcdh.signature , os ) ; 00124 writeUint16( zcdh.writer_version , os ) ; 00125 writeUint16( zcdh.extract_version , os ) ; 00126 writeUint16( zcdh.gp_bitfield , os ) ; 00127 writeUint16( zcdh.compress_method , os ) ; 00128 writeUint16( zcdh.last_mod_ftime , os ) ; 00129 writeUint16( zcdh.last_mod_fdate , os ) ; 00130 writeUint32( zcdh.crc_32 , os ) ; 00131 writeUint32( zcdh.compress_size , os ) ; 00132 writeUint32( zcdh.uncompress_size , os ) ; 00133 writeUint16( zcdh.filename_len , os ) ; 00134 writeUint16( zcdh.extra_field_len , os ) ; 00135 writeUint16( zcdh.file_comment_len , os ) ; 00136 writeUint16( zcdh.disk_num_start , os ) ; 00137 writeUint16( zcdh.intern_file_attr , os ) ; 00138 writeUint32( zcdh.extern_file_attr , os ) ; 00139 writeUint32( zcdh.rel_offset_loc_head, os ) ; 00140 00141 // Write filename and extra_field 00142 writeByteSeq( os, zcdh.filename ) ; 00143 writeByteSeq( os, zcdh.extra_field ) ; 00144 writeByteSeq( os, zcdh.file_comment ) ; 00145 00146 return os ; 00147 } 00148 00149 std::ostream &operator<< ( std::ostream &os, const EndOfCentralDirectory &eocd ) { 00150 if ( ! os ) 00151 return os ; 00152 00153 writeUint32( eocd.signature , os ) ; 00154 writeUint16( eocd.disk_num , os ) ; 00155 writeUint16( eocd.cdir_disk_num , os ) ; 00156 writeUint16( eocd.cdir_entries , os ) ; 00157 writeUint16( eocd.cdir_tot_entries, os ) ; 00158 writeUint32( eocd.cdir_size , os ) ; 00159 writeUint32( eocd.cdir_offset , os ) ; 00160 writeUint16( eocd.zip_comment_len , os ) ; 00161 00162 writeByteSeq( os, eocd.zip_comment ) ; 00163 00164 return os ; 00165 } 00166 00167 00168 00169 } // namespace 00170 00171 00172 00178 /* 00179 Zipios++ - a small C++ library that provides easy access to .zip files. 00180 Copyright (C) 2000 Thomas Søndergaard 00181 00182 This library is free software; you can redistribute it and/or 00183 modify it under the terms of the GNU Lesser General Public 00184 License as published by the Free Software Foundation; either 00185 version 2 of the License, or (at your option) any later version. 00186 00187 This library is distributed in the hope that it will be useful, 00188 but WITHOUT ANY WARRANTY; without even the implied warranty of 00189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00190 Lesser General Public License for more details. 00191 00192 You should have received a copy of the GNU Lesser General Public 00193 License along with this library; if not, write to the Free Software 00194 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00195 */