gzipstream.cpp revision 9cb13c55c8d4edc1a73902066fb300c975612e62
/*
* Zlib-enabled input and output streams
*
* This is a thin wrapper of libz calls, in order
* to provide a simple interface to our developers
* for gzip input and output.
*
* Authors:
* Bob Jamison <rjamison@titan.com>
*
* Copyright (C) 2004 Inkscape.org
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "gzipstream.h"
#include <cstdio>
#include <cstring>
#include <string>
namespace Inkscape
{
namespace IO
{
//#########################################################################
//# G Z I P I N P U T S T R E A M
//#########################################################################
#define OUT_SIZE 4000
/**
*
*/
loaded(false),
totalIn(0),
totalOut(0),
crc(0),
srcCrc(0),
srcSiz(0),
srcConsumed(0),
srcLen(0),
outputBufPos(0),
outputBufLen(0)
{
}
/**
*
*/
{
close();
if ( srcBuf ) {
}
if ( outputBuf ) {
}
}
/**
* Returns the number of bytes that can be read (or skipped over) from
* this input stream without blocking by the next caller of a method for
* this input stream.
*/
int GzipInputStream::available()
{
return 0;
return outputBufLen - outputBufPos;
}
/**
* Closes this input stream and releases any system resources
* associated with the stream.
*/
void GzipInputStream::close()
{
if (closed)
return;
}
if ( srcBuf ) {
}
if ( outputBuf ) {
}
closed = true;
}
/**
* Reads the next byte of data from the input stream. -1 if EOF
*/
int GzipInputStream::get()
{
int ch = -1;
if (closed) {
// leave return value -1
}
closed=true;
} else {
loaded = true;
if ( outputBufPos >= outputBufLen ) {
// time to read more, if we can
fetchMore();
}
if ( outputBufPos < outputBufLen ) {
}
}
return ch;
}
#define FTEXT 0x01
#define FHCRC 0x02
#define FEXTRA 0x04
#define FNAME 0x08
#define FCOMMENT 0x10
bool GzipInputStream::load()
{
while (true)
{
if (ch<0)
break;
}
{
return false;
}
if (!srcBuf) {
return false;
}
if ( !outputBuf ) {
srcBuf = 0;
return false;
}
outputBufLen = 0; // Not filled in yet
*p++ = *iter;
int headerLen = 10;
//Magic
//printf("val:%x\n", val);
//printf("val:%x\n", val);
//Method
//printf("val:%x\n", val);
//flags
//time
//xflags
//OS
// if ( flags & FEXTRA ) {
// headerLen += 2;
// int xlen =
// TODO deal with optional header parts
// }
int cur = 10;
{
cur++;
headerLen++;
}
headerLen++;
}
//printf("srcCrc:%lx\n", srcCrc);
//printf("srcSiz:%lx/%ld\n", srcSiz, srcSiz);
//outputBufLen = srcSiz + srcSiz/100 + 14;
//printf("%x %x\n", data[0], data[dataLen-1]);
{
} else {
}
}
int GzipInputStream::fetchMore()
{
// TODO assumes we aren't called till the buffer is empty
outputBufLen = 0;
outputBufPos = 0;
if ( outputBufLen ) {
}
//printf("crc:%lx\n", crc);
// } else if ( zerr != Z_STREAM_END ) {
// // TODO check to be sure this won't happen for partial end reads
// printf("inflate: Some kind of problem: %d\n", zerr);
}
return zerr;
}
//#########################################################################
//# G Z I P O U T P U T S T R E A M
//#########################################################################
/**
*
*/
{
totalIn = 0;
totalOut = 0;
//Gzip header
//Say it is compressed
//flags
destination.put(0);
//time
destination.put(0);
destination.put(0);
destination.put(0);
destination.put(0);
//xflags
destination.put(0);
//OS code - from zutil.h
//destination.put(OS_CODE);
//apparently, we should not explicitly include zutil.h
destination.put(0);
}
/**
*
*/
{
close();
}
/**
* Closes this output stream and releases any system resources
* associated with this stream.
*/
void GzipOutputStream::close()
{
if (closed)
return;
flush();
//# Send the CRC
for (int n = 0; n < 4; n++)
{
outlong >>= 8;
}
//# send the file length
for (int n = 0; n < 4; n++)
{
outlong >>= 8;
}
destination.close();
closed = true;
}
/**
* Flushes this output stream and forces any buffered output
* bytes to be written out.
*/
void GzipOutputStream::flush()
{
return;
if (!srcbuf)
{
return;
}
if (!destbuf)
{
return;
}
*p++ = *iter;
{
printf("Some kind of problem\n");
}
//skip the redundant zlib header and checksum
{
}
destination.flush();
//printf("done\n");
}
/**
* Writes the specified byte to this output stream.
*/
{
if (closed)
{
//probably throw an exception here
return;
}
//Add char to buffer
totalIn++;
}
} // namespace IO
} // namespace Inkscape
//#########################################################################
//# E N D O F F I L E
//#########################################################################
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :