From 23dccd1af2df6ed8f2954151a081263a45da3b61 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 19 Feb 2005 07:50:00 +0000 Subject: [PATCH] GzipString, GunzipString --- stepmania/src/RageFileDriverDeflate.cpp | 38 +++++++++++++++++++++++++ stepmania/src/RageFileDriverDeflate.h | 4 +++ 2 files changed, 42 insertions(+) diff --git a/stepmania/src/RageFileDriverDeflate.cpp b/stepmania/src/RageFileDriverDeflate.cpp index bbf66907c0..c2fa386cb2 100644 --- a/stepmania/src/RageFileDriverDeflate.cpp +++ b/stepmania/src/RageFileDriverDeflate.cpp @@ -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. diff --git a/stepmania/src/RageFileDriverDeflate.h b/stepmania/src/RageFileDriverDeflate.h index 059493f484..44fc3ca156 100644 --- a/stepmania/src/RageFileDriverDeflate.h +++ b/stepmania/src/RageFileDriverDeflate.h @@ -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 /*