File indexing completed on 2025-08-03 08:20:35
0001
0002 #include "ogzBuffer.h"
0003 #include "BufferConstants.h"
0004
0005
0006
0007 #ifndef WIN32
0008 ogzBuffer::ogzBuffer (int fdin, PHDWORD * where,
0009 const int length,
0010 const int level,
0011 const int irun,
0012 const int iseq):
0013 ophBuffer(fdin,where,length,irun,iseq)
0014 #else
0015 ogzBuffer::ogzBuffer (const char *fpp, PHDWORD * where,
0016 const int length,
0017 int & status,
0018 const int level,
0019 const int irun,
0020 const int iseq):
0021 ophBuffer(fpp,where,length,status,irun,iseq)
0022 #endif
0023 {
0024
0025
0026 compressionlevel = level;
0027 outputarraylength = (int)(length *1.1) + 2048;
0028 outputarray = new PHDWORD[outputarraylength];
0029
0030 }
0031
0032
0033
0034
0035 int ogzBuffer::writeout()
0036 {
0037 if (! dirty) return 0;
0038
0039 if (! has_end) addEoB();
0040
0041 uLongf outputlength_in_bytes = outputarraylength*4;
0042 uLong bytes_to_be_written = bptr->Length;
0043
0044 compress2 ( (Bytef*) &outputarray[4], &outputlength_in_bytes, (Bytef*) bptr,
0045 bytes_to_be_written, compressionlevel);
0046
0047 outputarray[0] = outputlength_in_bytes +4*BUFFERHEADERLENGTH;
0048 outputarray[1] = GZBUFFERMARKER;
0049 outputarray[2] = bptr->Bufseq;
0050 outputarray[3] = bptr->Length;
0051
0052 unsigned int ip =0;
0053 char *cp = (char *) outputarray;
0054
0055 while (ip<outputarray[0])
0056 {
0057 int n = write ( fd, cp, BUFFERBLOCKSIZE);
0058 if ( n != BUFFERBLOCKSIZE)
0059 {
0060 std::cout << " could not write output, bytes written: " << n << std::endl;
0061 return 0;
0062 }
0063 cp += BUFFERBLOCKSIZE;
0064 ip += BUFFERBLOCKSIZE;
0065 }
0066 dirty = 0;
0067 byteswritten += ip;
0068 return 0;
0069 }
0070
0071
0072
0073 ogzBuffer::~ogzBuffer()
0074 {
0075 writeout();
0076 delete [] outputarray;
0077
0078 }
0079