aboutsummaryrefslogtreecommitdiff
path: root/src/serializerbzip2.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
commitf4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch)
tree13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/serializerbzip2.cpp
parent74d4c8cd27334fc7204d5a8773deb3d424565778 (diff)
downloadlibbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip
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.
Diffstat (limited to 'src/serializerbzip2.cpp')
-rw-r--r--src/serializerbzip2.cpp88
1 files changed, 0 insertions, 88 deletions
diff --git a/src/serializerbzip2.cpp b/src/serializerbzip2.cpp
deleted file mode 100644
index bafabc8..0000000
--- a/src/serializerbzip2.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
1#include "serializerbzip2.h"
2#include "serializable.h"
3
4#include <bzlib.h>
5
6SerializerBZip2::SerializerBZip2(FILE *fhFile, bool bLoading):
7 Serializer(bLoading),
8 fhFile(fhFile),
9 bCloseFile(false)
10{
11 if( bLoading )
12 {
13 bzFile = BZ2_bzReadOpen( &bzerror, fhFile, 0, 0, NULL, 0 );
14 checkBZError();
15 }
16 else
17 {
18 bzFile = BZ2_bzWriteOpen( &bzerror, fhFile, 9, 0, 0 );
19 checkBZError();
20 }
21}
22
23SerializerBZip2::SerializerBZip2(char *sFileName, bool bLoading):
24 Serializer(bLoading),
25 bCloseFile(true)
26{
27 if (bLoading)
28 {
29 fhFile = fopen(sFileName, "rb");
30 bzFile = BZ2_bzReadOpen( &bzerror, fhFile, 0, 0, NULL, 0 );
31 checkBZError();
32 }
33 else
34 {
35 fhFile = fopen(sFileName, "wb");
36 bzFile = BZ2_bzWriteOpen( &bzerror, fhFile, 9, 0, 0 );
37 checkBZError();
38 }
39}
40
41SerializerBZip2::~SerializerBZip2()
42{
43 close();
44}
45
46void SerializerBZip2::checkBZError()
47{
48}
49
50void SerializerBZip2::close()
51{
52 if( bzFile != NULL )
53 {
54 if( isLoading() )
55 {
56 void *unused;
57 int nUnused;
58 BZ2_bzReadGetUnused( &bzerror, bzFile, &unused, &nUnused );
59 BZ2_bzReadClose( &bzerror, bzFile );
60 if( nUnused )
61 fseek( fhFile, -nUnused, SEEK_CUR );
62 }
63 else
64 {
65 BZ2_bzWriteClose( &bzerror, bzFile, 0, 0, 0 );
66 }
67 checkBZError();
68 bzFile = NULL;
69 }
70 if( fhFile != NULL && bCloseFile )
71 {
72 fclose(fhFile);
73 fhFile = NULL;
74 }
75}
76
77void SerializerBZip2::write(const void * pData, int32_t nSize)
78{
79 BZ2_bzWrite( &bzerror, bzFile, (void *)pData, nSize );
80 checkBZError();
81}
82
83void SerializerBZip2::read(void * pData, int32_t nSize)
84{
85 BZ2_bzRead( &bzerror, bzFile, pData, nSize );
86 checkBZError();
87}
88