/* Write the gzip footer. */
int RageFileObjGzip::Finish()
{
	/* We're about to write to the underlying file (so the footer isn't
	 * compressed).  Flush the compressed data first. */
	if( this->Flush() == -1 )
		return -1;

	/* Read the CRC of the data that's been written. */
	uint32_t iCRC;
	bool bOK = this->GetCRC32( &iCRC );
	ASSERT( bOK );

	/* Figure out the size of the data. */
	uint32_t iSize = Tell() - m_iDataStartOffset;

	/* Write the CRC and size directly to the file, so they don't get compressed. */
	iCRC = Swap32LE( iCRC );
	if( m_pFile->Write( &iCRC, sizeof(iCRC) ) == -1 )
	{
		SetError( m_pFile->GetError() );
		return -1;
	}

	/* Write the size. */
	iSize = Swap32LE( iSize );
	if( m_pFile->Write( &iSize, sizeof(iSize) ) == -1 )
	{
		SetError( m_pFile->GetError() );
		return -1;
	}
	
	/* Flush the CRC and wize that we just wrote directly to the file. */
	return m_pFile->Flush();
}
Esempio n. 2
0
int32_t FileReading::read_32_le( RageFileBasic &f, RString &sError )
{
	int32_t val;
	ReadBytes( f, &val, sizeof(int32_t), sError );
	if( sError.size() == 0 )
		return Swap32LE( val );
	else
		return 0;
}
static void write_le32( RageFile &f, RString &sError, uint32_t val )
{
	val = Swap32LE( val );
	WriteBytes( f, sError, &val, sizeof(uint32_t) );
}