|
Last change
on this file since 1159 was 834, checked in by garnier, 17 years ago |
|
import all except CVS
|
-
Property svn:executable
set to
*
|
|
File size:
1.9 KB
|
| Line | |
|---|
| 1 | // Copyright FreeHEP, 2005.
|
|---|
| 2 |
|
|---|
| 3 | #include "cheprep/GZIPOutputStreamBuffer.h"
|
|---|
| 4 |
|
|---|
| 5 | /**
|
|---|
| 6 | * @author Mark Donszelmann
|
|---|
| 7 | * @version $Id: GZIPOutputStreamBuffer.cc,v 1.4 2005/06/02 21:28:45 duns Exp $
|
|---|
| 8 | */
|
|---|
| 9 | namespace cheprep {
|
|---|
| 10 |
|
|---|
| 11 | using namespace std;
|
|---|
| 12 |
|
|---|
| 13 | GZIPOutputStreamBuffer::GZIPOutputStreamBuffer( streambuf *buffer)
|
|---|
| 14 | : DeflateOutputStreamBuffer(buffer),
|
|---|
| 15 | open(false) {
|
|---|
| 16 |
|
|---|
| 17 | init(true);
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | void GZIPOutputStreamBuffer::setFilename( const string &name ) {
|
|---|
| 21 | filename = name ;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | void GZIPOutputStreamBuffer::setComment( const string &c ) {
|
|---|
| 25 | comment = c ;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | void GZIPOutputStreamBuffer::close() {
|
|---|
| 29 | if (!open) return;
|
|---|
| 30 |
|
|---|
| 31 | finish();
|
|---|
| 32 | writeTrailer();
|
|---|
| 33 |
|
|---|
| 34 | open = false ;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | GZIPOutputStreamBuffer::~GZIPOutputStreamBuffer() {
|
|---|
| 38 | close() ;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | int GZIPOutputStreamBuffer::overflow( int c ) {
|
|---|
| 42 | if (!open) {
|
|---|
| 43 | writeHeader();
|
|---|
| 44 | open = true;
|
|---|
| 45 | }
|
|---|
| 46 | return DeflateOutputStreamBuffer::overflow( c ) ;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void GZIPOutputStreamBuffer::writeHeader() {
|
|---|
| 50 | unsigned char flag = 0x00;
|
|---|
| 51 | flag |= (filename == "") ? 0x00 : 0x08;
|
|---|
| 52 | flag |= (comment == "") ? 0x00 : 0x10;
|
|---|
| 53 |
|
|---|
| 54 | putUB(0x1f); // Magic #
|
|---|
| 55 | putUB(0x8b); // Magic #
|
|---|
| 56 | putUB(0x08); // Deflater.DEFLATED
|
|---|
| 57 | putUB(flag); // FLG
|
|---|
| 58 | putUI(0x00000000); // MTIME
|
|---|
| 59 | putUB(0x00); // XFLG
|
|---|
| 60 | putUB(0x00); // OS
|
|---|
| 61 |
|
|---|
| 62 | if (filename != "") {
|
|---|
| 63 | putS(filename); // Filename
|
|---|
| 64 | putUB(0x00);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if (comment != "") {
|
|---|
| 68 | putS(comment); // Comment
|
|---|
| 69 | putUB(0x00);
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | void GZIPOutputStreamBuffer::writeTrailer() {
|
|---|
| 74 | putUI(getCRC());
|
|---|
| 75 | putUI(getSize());
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | } // cheprep
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.