4#include "zipios++/zipios-config.h"
6#include "zipios++/meta-iostreams.h"
20inline uint16 ztohs (
unsigned char *buf ) {
24 out = (
static_cast< uint16
>( buf[ 0 ] ) << 8 ) +
25 (
static_cast< uint16
>( buf[ 1 ] ) ) ;
31inline uint32 ztohl (
unsigned char *buf ) {
33 out = (
static_cast< uint32
>( buf[ 0 ] ) << 24 ) +
34 (
static_cast< uint32
>( buf[ 1 ] ) << 16 ) +
35 (
static_cast< uint32
>( buf[ 2 ] ) << 8 ) +
36 (
static_cast< uint32
>( buf[ 3 ] ) ) ;
43inline uint16 ztohs (
unsigned char *buf ) {
45 out = (
static_cast< uint16
>( buf[ 1 ] ) << 8 ) +
46 (
static_cast< uint16
>( buf[ 0 ] ) ) ;
51inline uint32 ztohl (
unsigned char *buf ) {
53 out = (
static_cast< uint32
>( buf[ 3 ] ) << 24 ) +
54 (
static_cast< uint32
>( buf[ 2 ] ) << 16 ) +
55 (
static_cast< uint32
>( buf[ 1 ] ) << 8 ) +
56 (
static_cast< uint32
>( buf[ 0 ] ) ) ;
69inline uint32 htozl (
unsigned char *buf ) {
74inline uint16 htozs (
unsigned char *buf ) {
79inline uint32 readUint32 ( istream &is ) {
80 static const int buf_len =
sizeof ( uint32 ) ;
81 unsigned char buf [ buf_len ] ;
83 std::streampos original_pos = is.tellg() ;
84 while ( rsf < buf_len && !is.eof() ) {
85 is.read (
reinterpret_cast< char *
>( buf ) + rsf, buf_len - rsf ) ;
88 if ( rsf != buf_len ) {
89 is.seekg( original_pos ) ;
90 throw InvalidStateException(
"Reached end-of-file while trying to read a"
91 "Uint32; the zip archive may be corrupt." ) ;
93 return ztohl ( buf ) ;
96inline void writeUint32 ( uint32 host_val, ostream &os ) {
97 uint32 val = htozl(
reinterpret_cast< unsigned char *
>( &host_val ) ) ;
98 os.write(
reinterpret_cast< char *
>( &val ),
sizeof( uint32 ) ) ;
101inline uint16 readUint16 ( istream &is ) {
102 static const int buf_len =
sizeof ( uint16 ) ;
103 unsigned char buf [ buf_len ] ;
105 std::streampos original_pos = is.tellg() ;
106 while ( rsf < buf_len && !is.eof() ) {
107 is.read (
reinterpret_cast< char *
>( buf ) + rsf, buf_len - rsf ) ;
108 rsf += is.gcount () ;
110 if ( rsf != buf_len ) {
111 is.seekg( original_pos ) ;
112 throw InvalidStateException(
"Reached end-of-file while trying to read a"
113 "Uint16; the zip archive may be corrupt." ) ;
115 return ztohs ( buf ) ;
118inline void writeUint16 ( uint16 host_val, ostream &os ) {
119 uint16 val = htozl(
reinterpret_cast< unsigned char *
>( &host_val ) ) ;
120 os.write(
reinterpret_cast< char *
>( &val ),
sizeof( uint16 ) ) ;
123inline void readByteSeq ( istream &is,
string &con,
int count ) {
124 char *buf =
new char [ count + 1 ] ;
126 while ( rsf < count && is ) {
127 is.read ( buf + rsf, count - rsf ) ;
130 buf [ count ] =
'\0' ;
136inline void writeByteSeq( ostream &os,
const string &con ) {
140inline void readByteSeq ( istream &is,
unsigned char *buf,
int count ) {
143 while ( rsf < count && is ) {
144 is.read (
reinterpret_cast< char *
>( buf ) + rsf, count - rsf ) ;
149inline void writeByteSeq ( ostream &os,
const unsigned char *buf,
int count ) {
150 os.rdbuf()->sputn(
reinterpret_cast< const char *
>( buf ), count ) ;
153inline void readByteSeq ( istream &is, vector < unsigned char > &vec,
int count ) {
154 unsigned char *buf =
new unsigned char [ count ] ;
156 while ( rsf < count && is ) {
157 is.read (
reinterpret_cast< char *
>( buf ) + rsf, count - rsf ) ;
161 vec.insert ( vec.end (), buf, buf + count ) ;
165inline void writeByteSeq ( ostream &os,
const vector < unsigned char > &vec ) {
166 os.rdbuf()->sputn(
reinterpret_cast< const char *
>( &( vec[ 0 ] ) ), vec.size() ) ;
169istream& operator>> ( istream &is, ZipLocalEntry &zlh ) ;
170istream& operator>> ( istream &is, DataDescriptor &dd ) ;
171istream& operator>> ( istream &is, ZipCDirEntry &zcdh ) ;
174ostream &operator<< ( ostream &os,
const ZipLocalEntry &zlh ) ;
175ostream &operator<< ( ostream &os,
const ZipCDirEntry &zcdh ) ;
176ostream &operator<< ( ostream &os,
const EndOfCentralDirectory &eocd ) ;
Header file that defines a number of exceptions used by FileCollection and its subclasses.
Header file containing classes and functions for reading the central directory and local header field...
Header file that defines some simple data types.