aboutsummaryrefslogtreecommitdiff
path: root/src/old/serializerbzip2.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-03 00:28:59 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-03 00:28:59 +0000
commitac517a2b7625e0aa0862679e961c6349f859ea3b (patch)
treee3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/old/serializerbzip2.cpp
parentf8d4301e9fa4f3709258505941e37fab2eadadc6 (diff)
parentbd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff)
downloadlibbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz
libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2
libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz
libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to 'src/old/serializerbzip2.cpp')
-rw-r--r--src/old/serializerbzip2.cpp88
1 files changed, 88 insertions, 0 deletions
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 @@
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