From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/old/serializerbzip2.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/old/serializerbzip2.cpp (limited to 'src/old/serializerbzip2.cpp') diff --git a/src/old/serializerbzip2.cpp b/src/old/serializerbzip2.cpp new file mode 100644 index 0000000..bafabc8 --- /dev/null +++ b/src/old/serializerbzip2.cpp @@ -0,0 +1,88 @@ +#include "serializerbzip2.h" +#include "serializable.h" + +#include + +SerializerBZip2::SerializerBZip2(FILE *fhFile, bool bLoading): + Serializer(bLoading), + fhFile(fhFile), + bCloseFile(false) +{ + if( bLoading ) + { + bzFile = BZ2_bzReadOpen( &bzerror, fhFile, 0, 0, NULL, 0 ); + checkBZError(); + } + else + { + bzFile = BZ2_bzWriteOpen( &bzerror, fhFile, 9, 0, 0 ); + checkBZError(); + } +} + +SerializerBZip2::SerializerBZip2(char *sFileName, bool bLoading): + Serializer(bLoading), + bCloseFile(true) +{ + if (bLoading) + { + fhFile = fopen(sFileName, "rb"); + bzFile = BZ2_bzReadOpen( &bzerror, fhFile, 0, 0, NULL, 0 ); + checkBZError(); + } + else + { + fhFile = fopen(sFileName, "wb"); + bzFile = BZ2_bzWriteOpen( &bzerror, fhFile, 9, 0, 0 ); + checkBZError(); + } +} + +SerializerBZip2::~SerializerBZip2() +{ + close(); +} + +void SerializerBZip2::checkBZError() +{ +} + +void SerializerBZip2::close() +{ + if( bzFile != NULL ) + { + if( isLoading() ) + { + void *unused; + int nUnused; + BZ2_bzReadGetUnused( &bzerror, bzFile, &unused, &nUnused ); + BZ2_bzReadClose( &bzerror, bzFile ); + if( nUnused ) + fseek( fhFile, -nUnused, SEEK_CUR ); + } + else + { + BZ2_bzWriteClose( &bzerror, bzFile, 0, 0, 0 ); + } + checkBZError(); + bzFile = NULL; + } + if( fhFile != NULL && bCloseFile ) + { + fclose(fhFile); + fhFile = NULL; + } +} + +void SerializerBZip2::write(const void * pData, int32_t nSize) +{ + BZ2_bzWrite( &bzerror, bzFile, (void *)pData, nSize ); + checkBZError(); +} + +void SerializerBZip2::read(void * pData, int32_t nSize) +{ + BZ2_bzRead( &bzerror, bzFile, pData, nSize ); + checkBZError(); +} + -- cgit v1.2.3