diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-06-10 21:28:14 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-06-10 21:28:14 +0000 |
commit | 5f39066a4f561e9a94a6cc9293ab9b978ebf1f81 (patch) | |
tree | a25698caf9594feecae8b71f032a11f81ba6cc3c /src/bzip2.cpp | |
parent | f5352edf3dc23c044a91f1d1537fa0dc0f0babc7 (diff) | |
download | libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.tar.gz libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.tar.bz2 libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.tar.xz libbu++-5f39066a4f561e9a94a6cc9293ab9b978ebf1f81.zip |
Bunch of maintenence type things. Minor tweaks and the like. The file class
has a lot more helper functions and the like, the filters give more info back
to the caller, minor updates to taf.
Diffstat (limited to 'src/bzip2.cpp')
-rw-r--r-- | src/bzip2.cpp | 41 |
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 | ||
29 | void Bu::BZip2::stop() | 29 | size_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 | ||
58 | void Bu::BZip2::bzError( int code ) | 62 | void 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 | ||