#include "LogSingleton.h"
#include <stdexcept>
-using namespace std;
+
#include <errno.h>
#include <memory.h>
#include <malloc.h>
lasterr(0),
compression_type (COMPRESSION_UNKNOWN)
{
- unsigned char * out_block = NULL;
- unsigned char * in_block = NULL;
-
/* read only */
if (!parent || parent->error())
{
}
original = parent;
+ create ();
+ init_decoder ();
+}
+
+void
+compress_xz::create ()
+{
+ unsigned char * out_block = NULL;
+ unsigned char * in_block = NULL;
+
state = (struct private_data *)calloc(sizeof(*state), 1);
out_block = (unsigned char *)malloc(out_block_size);
in_block = (unsigned char *)malloc(in_block_size);
state->out_block = out_block;
state->in_block_size = in_block_size;
state->in_block = in_block;
- state->out_p = out_block;
+ state->out_p = state->out_block;
state->stream.avail_in = 0;
state->stream.next_out = state->out_block;
state->stream.avail_out = state->out_block_size;
-
- init_decoder ();
}
ssize_t
{
/* no compressed data ready; read some more */
state->in_size = (size_t) this->original->read(state->in_block, state->in_block_size);
+ /* We don't care for error vs EOF */
+ if (state->in_size < 0)
+ state->in_size = 0;
state->in_pos = 0;
}
ssize_t
compress_xz::write (const void *buffer, size_t len)
{
- throw new logic_error("compress_xz::write is not implemented");
+ throw new std::logic_error("compress_xz::write is not implemented");
}
ssize_t
return 0;
}
-long
+off_t
compress_xz::tell ()
{
- throw new logic_error("compress_xz::tell is not implemented");
+ throw new std::logic_error("compress_xz::tell is not implemented");
}
-int
-compress_xz::seek (long where, io_stream_seek_t whence)
+off_t
+compress_xz::seek (off_t where, io_stream_seek_t whence)
{
- throw new logic_error("compress_xz::seek is not implemented");
+ if ((whence == IO_SEEK_SET) && (where == 0))
+ {
+ off_t result = original->seek(where, whence);
+ destroy ();
+ peeklen = 0;
+ lasterr = 0;
+ create ();
+ init_decoder ();
+ return result;
+ }
+
+ throw new std::logic_error("compress_xz::seek is not implemented");
}
int
compression_type = COMPRESSION_UNKNOWN;
}
-
- if (original && owns_original)
- delete original;
}
compress_xz::~compress_xz ()
{
destroy ();
+
+ if (original && owns_original)
+ delete original;
}
/* ===========================================================================
return 0;
bits_checked += 8;
+#ifdef DEBUG
LogBabblePrintf ("compress_xz::bid_xz: success: %d\n", bits_checked);
+#endif
return (bits_checked);
}
/* TODO: The above test is still very weak. It would be
* good to do better. */
+#ifdef DEBUG
LogBabblePrintf ("compress_xz::bid_lzma: success: %d\n", bits_checked);
+#endif
return (bits_checked);
}
-
-