summaryrefslogtreecommitdiff
path: root/src/bzip2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bzip2.cpp')
-rw-r--r--src/bzip2.cpp41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/bzip2.cpp b/src/bzip2.cpp
index 433fc91..5423a10 100644
--- a/src/bzip2.cpp
+++ b/src/bzip2.cpp
@@ -26,16 +26,18 @@ void Bu::BZip2::start()
26 pBuf = new char[nBufSize]; 26 pBuf = new char[nBufSize];
27} 27}
28 28
29void Bu::BZip2::stop() 29size_t Bu::BZip2::stop()
30{ 30{
31 if( bzState.state ) 31 if( bzState.state )
32 { 32 {
33 if( bReading ) 33 if( bReading )
34 { 34 {
35 BZ2_bzDecompressEnd( &bzState ); 35 BZ2_bzDecompressEnd( &bzState );
36 return 0;
36 } 37 }
37 else 38 else
38 { 39 {
40 size_t sTotal = 0;
39 for(;;) 41 for(;;)
40 { 42 {
41 bzState.next_in = NULL; 43 bzState.next_in = NULL;
@@ -45,14 +47,16 @@ void Bu::BZip2::stop()
45 int res = BZ2_bzCompress( &bzState, BZ_FINISH ); 47 int res = BZ2_bzCompress( &bzState, BZ_FINISH );
46 if( bzState.avail_out < nBufSize ) 48 if( bzState.avail_out < nBufSize )
47 { 49 {
48 rNext.write( pBuf, nBufSize-bzState.avail_out ); 50 sTotal += rNext.write( pBuf, nBufSize-bzState.avail_out );
49 } 51 }
50 if( res == BZ_STREAM_END ) 52 if( res == BZ_STREAM_END )
51 break; 53 break;
52 } 54 }
53 BZ2_bzCompressEnd( &bzState ); 55 BZ2_bzCompressEnd( &bzState );
56 return sTotal;
54 } 57 }
55 } 58 }
59 return 0;
56} 60}
57 61
58void Bu::BZip2::bzError( int code ) 62void Bu::BZip2::bzError( int code )
@@ -63,13 +67,35 @@ void Bu::BZip2::bzError( int code )
63 return; 67 return;
64 68
65 case BZ_CONFIG_ERROR: 69 case BZ_CONFIG_ERROR:
66 throw ExceptionBase("The bzip2 library has been miscompiled."); 70 throw ExceptionBase("BZip2: Library configured improperly, reinstall.");
71
72 case BZ_SEQUENCE_ERROR:
73 throw ExceptionBase("BZip2: Functions were called in an invalid sequence.");
67 74
68 case BZ_PARAM_ERROR: 75 case BZ_PARAM_ERROR:
69 throw ExceptionBase("bzip2 parameter error."); 76 throw ExceptionBase("BZip2: Invalid parameter was passed into a function.");
70 77
71 case BZ_MEM_ERROR: 78 case BZ_MEM_ERROR:
72 throw ExceptionBase("Not enough memory available for bzip2."); 79 throw ExceptionBase("BZip2: Couldn't allocate sufficient memory.");
80
81 case BZ_DATA_ERROR:
82 throw ExceptionBase("BZip2: Data was corrupted before decompression.");
83
84 case BZ_DATA_ERROR_MAGIC:
85 throw ExceptionBase("BZip2: Stream does not appear to be bzip2 data.");
86
87 case BZ_IO_ERROR:
88 throw ExceptionBase("BZip2: File couldn't be read from / written to.");
89
90 case BZ_UNEXPECTED_EOF:
91 throw ExceptionBase("BZip2: End of file encountered before end of stream.");
92
93 case BZ_OUTBUFF_FULL:
94 throw ExceptionBase("BZip2: Buffer not large enough to accomidate data.");
95
96 default:
97 throw ExceptionBase("BZip2: Unknown error encountered.");
98
73 } 99 }
74} 100}
75 101
@@ -124,6 +150,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes )
124 if( bReading == true ) 150 if( bReading == true )
125 throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); 151 throw ExceptionBase("This bzip2 filter is in reading mode, you can't write.");
126 152
153 size_t sTotalOut = 0;
127 bzState.next_in = (char *)pData; 154 bzState.next_in = (char *)pData;
128 bzState.avail_in = nBytes; 155 bzState.avail_in = nBytes;
129 for(;;) 156 for(;;)
@@ -135,12 +162,12 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes )
135 162
136 if( bzState.avail_out < nBufSize ) 163 if( bzState.avail_out < nBufSize )
137 { 164 {
138 rNext.write( pBuf, nBufSize-bzState.avail_out ); 165 sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out );
139 } 166 }
140 if( bzState.avail_in == 0 ) 167 if( bzState.avail_in == 0 )
141 break; 168 break;
142 } 169 }
143 170
144 return 0; 171 return sTotalOut;
145} 172}
146 173