Game Development Reference
In-Depth Information
2.
Read compressed data from a .zip ile. This indirection actually allows to access
archives inside the other archives:
static uLong ZCALLBACK zip_fread( voidpf opaque, voidpf stream,
void* buf, uLong size )
{
iIStream* S = ( iIStream* )stream;
int64_t CanRead = ( int64 )size;
int64_t Sz = S->GetFileSize();
int64_t Ps = S->GetFilePos();
if ( CanRead + Ps >= Sz ) { CanRead = Sz - Ps; }
if ( CanRead > 0 )
{ S->BlockRead( buf, (uint64_t)CanRead ); }
else
{ CanRead = 0; }
return ( uLong )CanRead;
}
3.
Return the current position inside a .zip ile:
static ZPOS64_T ZCALLBACK zip_ftell( voidpf opaque,
voidpf stream )
{
return ( ZPOS64_T )( ( iIStream* )stream )->GetFilePos();
}
4. Advance to the speciied position. The offset value is relative to the current position
( SEEK_CUR ), ile start ( SEEK_SET ), or ile end ( SEEK_END ):
static long ZCALLBACK zip_fseek ( voidpf opaque, voidpf stream,
ZPOS64_T offset, int origin )
{
iIStream* S = ( iIStream* )stream;
int64 NewPos = ( int64 )offset;
int64 Sz = ( int64 )S->GetFileSize();
switch ( origin )
{
case ZLIB_FILEFUNC_SEEK_CUR:
NewPos += ( int64 )S->GetFilePos();
break;
case ZLIB_FILEFUNC_SEEK_END:
NewPos = Sz - 1 - NewPos;
break;
case ZLIB_FILEFUNC_SEEK_SET:
break;
default:
return -1;
 
Search WWH ::




Custom Search