GzipString, GunzipString

This commit is contained in:
Glenn Maynard
2005-02-19 07:50:00 +00:00
parent d1fb6a41eb
commit 23dccd1af2
2 changed files with 42 additions and 0 deletions
+38
View File
@@ -487,6 +487,44 @@ int RageFileObjGzip::Finish()
return this->Flush();
}
#include "RageFileDriverMemory.h"
void GzipString( const CString &sIn, CString &sOut )
{
/* Gzip it. */
RageFileObjMem mem;
RageFileObjGzip gzip( &mem );
gzip.Start();
gzip.Write( sIn );
gzip.Finish();
sOut = mem.GetString();
}
bool GunzipString( const CString &sIn, CString &sOut )
{
RageFileObjMem mem;
mem.PutString( sIn );
CString sError;
uint32_t iCRC32;
RageFileBasic *pFile = GunzipFile( mem, sError, &iCRC32 );
if( pFile == NULL )
return false;
pFile->Read( sOut );
/* Check the CRC. */
unsigned iRet;
ASSERT( pFile->GetCRC32( &iRet ) );
SAFE_DELETE( pFile );
if( iRet != iCRC32 )
return false;
return true;
}
/*
* Copyright (c) 2003-2004 Glenn Maynard
* All rights reserved.
+4
View File
@@ -68,6 +68,10 @@ private:
RageFileBasic *GunzipFile( RageFileBasic &file, CString &sError, uint32_t *iCRC32 );
/* Quick helpers: */
void GzipString( const CString &sIn, CString &sOut );
bool GunzipString( const CString &sIn, CString &sOut ); // returns false on CRC, etc. error
#endif
/*