4 #include "zipios++/zipios-config.h"
6 #include "zipios++/meta-iostreams.h"
19 inline uint16 ztohs (
unsigned char *buf ) {
23 out = (
static_cast< uint16
>( buf[ 0 ] ) << 8 ) +
24 (
static_cast< uint16
>( buf[ 1 ] ) ) ;
30 inline uint32 ztohl (
unsigned char *buf ) {
32 out = (
static_cast< uint32
>( buf[ 0 ] ) << 24 ) +
33 (
static_cast< uint32
>( buf[ 1 ] ) << 16 ) +
34 (
static_cast< uint32
>( buf[ 2 ] ) << 8 ) +
35 (
static_cast< uint32
>( buf[ 3 ] ) ) ;
42 inline uint16 ztohs (
unsigned char *buf ) {
44 out = (
static_cast< uint16
>( buf[ 1 ] ) << 8 ) +
45 (
static_cast< uint16
>( buf[ 0 ] ) ) ;
50 inline uint32 ztohl (
unsigned char *buf ) {
52 out = (
static_cast< uint32
>( buf[ 3 ] ) << 24 ) +
53 (
static_cast< uint32
>( buf[ 2 ] ) << 16 ) +
54 (
static_cast< uint32
>( buf[ 1 ] ) << 8 ) +
55 (
static_cast< uint32
>( buf[ 0 ] ) ) ;
68 inline uint32 htozl (
unsigned char *buf ) {
73 inline uint16 htozs (
unsigned char *buf ) {
78 inline uint32 readUint32 ( istream &is ) {
79 static const int buf_len =
sizeof ( uint32 ) ;
80 unsigned char buf [ buf_len ] ;
82 while ( rsf < buf_len ) {
83 is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
86 return ztohl ( buf ) ;
89 inline void writeUint32 ( uint32 host_val, ostream &os ) {
90 uint32 val = htozl( reinterpret_cast< unsigned char * >( &host_val ) ) ;
91 os.write( reinterpret_cast< char * >( &val ),
sizeof( uint32 ) ) ;
94 inline uint16 readUint16 ( istream &is ) {
95 static const int buf_len =
sizeof ( uint16 ) ;
96 unsigned char buf [ buf_len ] ;
98 while ( rsf < buf_len ) {
99 is.read ( reinterpret_cast< char * >( buf ) + rsf, buf_len - rsf ) ;
100 rsf += is.gcount () ;
102 return ztohs ( buf ) ;
105 inline void writeUint16 ( uint16 host_val, ostream &os ) {
106 uint16 val = htozl( reinterpret_cast< unsigned char * >( &host_val ) ) ;
107 os.write( reinterpret_cast< char * >( &val ),
sizeof( uint16 ) ) ;
110 inline void readByteSeq ( istream &is,
string &con,
int count ) {
111 char *buf =
new char [ count + 1 ] ;
113 while ( rsf < count && is ) {
114 is.read ( buf + rsf, count - rsf ) ;
117 buf [ count ] =
'\0' ;
123 inline void writeByteSeq( ostream &os,
const string &con ) {
127 inline void readByteSeq ( istream &is,
unsigned char *buf,
int count ) {
130 while ( rsf < count && is ) {
131 is.read ( reinterpret_cast< char * >( buf ) + rsf, count - rsf ) ;
136 inline void writeByteSeq ( ostream &os,
const unsigned char *buf,
int count ) {
137 os.rdbuf()->sputn( reinterpret_cast< const char * >( buf ), count ) ;
140 inline void readByteSeq ( istream &is, vector < unsigned char > &vec,
int count ) {
141 unsigned char *buf =
new unsigned char [ count ] ;
143 while ( rsf < count && is ) {
144 is.read ( reinterpret_cast< char * >( buf ) + rsf, count - rsf ) ;
148 vec.insert ( vec.end (), buf, buf + count ) ;
152 inline void writeByteSeq ( ostream &os,
const vector < unsigned char > &vec ) {
153 os.rdbuf()->sputn( reinterpret_cast< const char * >( &( vec[ 0 ] ) ), vec.size() ) ;
156 istream& operator>> ( istream &is, ZipLocalEntry &zlh ) ;
157 istream& operator>> ( istream &is, DataDescriptor &dd ) ;
158 istream& operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
161 ostream &operator<< ( ostream &os,
const ZipLocalEntry &zlh ) ;
162 ostream &operator<< ( ostream &os,
const ZipCDirEntry &zcdh ) ;
163 ostream &operator<< ( ostream &os,
const EndOfCentralDirectory &eocd ) ;
Header file that defines some simple data types.
Header file containing classes and functions for reading the central directory and local header field...