diff options
Diffstat (limited to 'src/old/serializerbzip2.cpp')
-rw-r--r-- | src/old/serializerbzip2.cpp | 88 |
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 | |||
6 | SerializerBZip2::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 | |||
23 | SerializerBZip2::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 | |||
41 | SerializerBZip2::~SerializerBZip2() | ||
42 | { | ||
43 | close(); | ||
44 | } | ||
45 | |||
46 | void SerializerBZip2::checkBZError() | ||
47 | { | ||
48 | } | ||
49 | |||
50 | void 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 | |||
77 | void SerializerBZip2::write(const void * pData, int32_t nSize) | ||
78 | { | ||
79 | BZ2_bzWrite( &bzerror, bzFile, (void *)pData, nSize ); | ||
80 | checkBZError(); | ||
81 | } | ||
82 | |||
83 | void SerializerBZip2::read(void * pData, int32_t nSize) | ||
84 | { | ||
85 | BZ2_bzRead( &bzerror, bzFile, pData, nSize ); | ||
86 | checkBZError(); | ||
87 | } | ||
88 | |||