diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-09-23 23:19:38 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-09-23 23:19:38 +0000 |
commit | 1b7caf3368675eb6825e0dca77782a141dfa0392 (patch) | |
tree | 01fb357534875c7a69199e4dd3f0c9d8810810e2 | |
parent | 319a773dfcb187bc7e87ae6d64df3b6b6ec4831a (diff) | |
download | libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.tar.gz libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.tar.bz2 libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.tar.xz libbu++-1b7caf3368675eb6825e0dca77782a141dfa0392.zip |
Wow, ok, file was broken on changing position in the stream, it wouldn't reset
the end of stream flag. Now it does reset it, and assumes that you've placed
the position not at the end, if you have, it will detect it again immediately
upon read.
BZip2 now provides a method of getting the number of bytes written out, i.e.
the compressed size of the output, I have to figure out the input side next...
Diffstat (limited to '')
-rwxr-xr-x | checkinst.sh | 2 | ||||
-rw-r--r-- | src/bzip2.cpp | 16 | ||||
-rw-r--r-- | src/bzip2.h | 3 | ||||
-rw-r--r-- | src/file.cpp | 3 |
4 files changed, 18 insertions, 6 deletions
diff --git a/checkinst.sh b/checkinst.sh index 957267c..cc0d0e9 100755 --- a/checkinst.sh +++ b/checkinst.sh | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | 2 | ||
3 | CMD="ln -svf $PWD/libbu++.so /usr/lib; ln -svf $PWD/bu /usr/include" | 3 | CMD="ln -svf $PWD/libbu++.so /usr/lib; ln -svf $PWD/bu /usr/include; ln -svf $PWD/libbu++.a /usr/lib" |
4 | 4 | ||
5 | if [ $UID == 0 ]; then | 5 | if [ $UID == 0 ]; then |
6 | bash -c "$CMD" | 6 | bash -c "$CMD" |
diff --git a/src/bzip2.cpp b/src/bzip2.cpp index 0a56f83..7f6e45e 100644 --- a/src/bzip2.cpp +++ b/src/bzip2.cpp | |||
@@ -12,7 +12,8 @@ using namespace Bu; | |||
12 | 12 | ||
13 | Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : | 13 | Bu::BZip2::BZip2( Bu::Stream &rNext, int nCompression ) : |
14 | Bu::Filter( rNext ), | 14 | Bu::Filter( rNext ), |
15 | nCompression( nCompression ) | 15 | nCompression( nCompression ), |
16 | sTotalOut( 0 ) | ||
16 | { | 17 | { |
17 | TRACE( nCompression ); | 18 | TRACE( nCompression ); |
18 | start(); | 19 | start(); |
@@ -50,7 +51,7 @@ size_t Bu::BZip2::stop() | |||
50 | } | 51 | } |
51 | else | 52 | else |
52 | { | 53 | { |
53 | size_t sTotal = 0; | 54 | // size_t sTotal = 0; |
54 | for(;;) | 55 | for(;;) |
55 | { | 56 | { |
56 | bzState.next_in = NULL; | 57 | bzState.next_in = NULL; |
@@ -60,7 +61,7 @@ size_t Bu::BZip2::stop() | |||
60 | int res = BZ2_bzCompress( &bzState, BZ_FINISH ); | 61 | int res = BZ2_bzCompress( &bzState, BZ_FINISH ); |
61 | if( bzState.avail_out < nBufSize ) | 62 | if( bzState.avail_out < nBufSize ) |
62 | { | 63 | { |
63 | sTotal += rNext.write( pBuf, nBufSize-bzState.avail_out ); | 64 | sTotalOut += rNext.write( pBuf, nBufSize-bzState.avail_out ); |
64 | } | 65 | } |
65 | if( res == BZ_STREAM_END ) | 66 | if( res == BZ_STREAM_END ) |
66 | break; | 67 | break; |
@@ -68,7 +69,7 @@ size_t Bu::BZip2::stop() | |||
68 | BZ2_bzCompressEnd( &bzState ); | 69 | BZ2_bzCompressEnd( &bzState ); |
69 | delete[] pBuf; | 70 | delete[] pBuf; |
70 | pBuf = NULL; | 71 | pBuf = NULL; |
71 | return sTotal; | 72 | return sTotalOut; |
72 | } | 73 | } |
73 | } | 74 | } |
74 | return 0; | 75 | return 0; |
@@ -182,7 +183,7 @@ size_t Bu::BZip2::write( const void *pData, size_t nBytes ) | |||
182 | if( bReading == true ) | 183 | if( bReading == true ) |
183 | throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); | 184 | throw ExceptionBase("This bzip2 filter is in reading mode, you can't write."); |
184 | 185 | ||
185 | size_t sTotalOut = 0; | 186 | // size_t sTotalOut = 0; |
186 | bzState.next_in = (char *)pData; | 187 | bzState.next_in = (char *)pData; |
187 | bzState.avail_in = nBytes; | 188 | bzState.avail_in = nBytes; |
188 | for(;;) | 189 | for(;;) |
@@ -209,3 +210,8 @@ bool Bu::BZip2::isOpen() | |||
209 | return (bzState.state != NULL); | 210 | return (bzState.state != NULL); |
210 | } | 211 | } |
211 | 212 | ||
213 | size_t Bu::BZip2::getCompressedSize() | ||
214 | { | ||
215 | return sTotalOut; | ||
216 | } | ||
217 | |||
diff --git a/src/bzip2.h b/src/bzip2.h index fd0ba5c..7ca61b4 100644 --- a/src/bzip2.h +++ b/src/bzip2.h | |||
@@ -32,6 +32,8 @@ namespace Bu | |||
32 | 32 | ||
33 | virtual bool isOpen(); | 33 | virtual bool isOpen(); |
34 | 34 | ||
35 | size_t getCompressedSize(); | ||
36 | |||
35 | private: | 37 | private: |
36 | void bzError( int code ); | 38 | void bzError( int code ); |
37 | bz_stream bzState; | 39 | bz_stream bzState; |
@@ -39,6 +41,7 @@ namespace Bu | |||
39 | int nCompression; | 41 | int nCompression; |
40 | char *pBuf; | 42 | char *pBuf; |
41 | uint32_t nBufSize; | 43 | uint32_t nBufSize; |
44 | size_t sTotalOut; | ||
42 | }; | 45 | }; |
43 | } | 46 | } |
44 | 47 | ||
diff --git a/src/file.cpp b/src/file.cpp index 6228ba9..1c26001 100644 --- a/src/file.cpp +++ b/src/file.cpp | |||
@@ -93,6 +93,7 @@ void Bu::File::seek( long offset ) | |||
93 | throw FileException("File not open."); | 93 | throw FileException("File not open."); |
94 | 94 | ||
95 | lseek( fd, offset, SEEK_CUR ); | 95 | lseek( fd, offset, SEEK_CUR ); |
96 | bEos = false; | ||
96 | } | 97 | } |
97 | 98 | ||
98 | void Bu::File::setPos( long pos ) | 99 | void Bu::File::setPos( long pos ) |
@@ -101,6 +102,7 @@ void Bu::File::setPos( long pos ) | |||
101 | throw FileException("File not open."); | 102 | throw FileException("File not open."); |
102 | 103 | ||
103 | lseek( fd, pos, SEEK_SET ); | 104 | lseek( fd, pos, SEEK_SET ); |
105 | bEos = false; | ||
104 | } | 106 | } |
105 | 107 | ||
106 | void Bu::File::setPosEnd( long pos ) | 108 | void Bu::File::setPosEnd( long pos ) |
@@ -109,6 +111,7 @@ void Bu::File::setPosEnd( long pos ) | |||
109 | throw FileException("File not open."); | 111 | throw FileException("File not open."); |
110 | 112 | ||
111 | lseek( fd, pos, SEEK_END ); | 113 | lseek( fd, pos, SEEK_END ); |
114 | bEos = false; | ||
112 | } | 115 | } |
113 | 116 | ||
114 | bool Bu::File::isEos() | 117 | bool Bu::File::isEos() |