49 memset(
mZStream, 0,
sizeof(z_stream_s));
60 memset(
mZStream, 0,
sizeof(z_stream_s));
78 Log::error(
"GZipCodec::open(): file already open.\n");
92 memset(
mZStream, 0,
sizeof(z_stream_s));
100 if ( inflateInit2(
mZStream, 15+32) != Z_OK )
102 Log::error(
"GZipCodec::open(): inflateInit2 failed.\n");
111 Log::error(
"GZipCodec::open(): deflateInit2 failed.\n");
122 Log::error(
"GZipCodec::open(): no input or output stream defined. See the setStream() method documentation.\n");
127 Log::error(
"GZipCodec::open(): input or output stream open failed.\n");
142 unsigned char next_out[CHUNK_SIZE];
143 unsigned char dummy_buffer=0;
145 mZStream->next_in = (Bytef*)&dummy_buffer;
150 int ret = deflate(
mZStream, Z_FINISH);
151 if (ret == Z_STREAM_ERROR)
153 Log::error(
"GZStream::write(): Z_STREAM_ERROR.\n");
155 memset(
mZStream, 0,
sizeof(z_stream_s));
158 unsigned have = CHUNK_SIZE -
mZStream->avail_out;
161 long long written =
stream()->
write(next_out, have);
170 memset(
mZStream, 0,
sizeof(z_stream_s));
181 file->operator=(*this);
188 super::operator=(other);
197 if ( bytes_to_read < 1 )
201 Log::error(
"GZStream::read(): read requested on closed stream.\n");
206 long long read_bytes = 0;
221 bytes_to_read -= bytes;
235 unsigned char next_out[CHUNK_SIZE];
236 mZStream->avail_in = (uInt)byte_count;
242 int ret = deflate(
mZStream, Z_NO_FLUSH);
243 if (ret == Z_STREAM_ERROR)
245 Log::error(
"GZStream::write(): Z_STREAM_ERROR.\n");
248 unsigned have = CHUNK_SIZE -
mZStream->avail_out;
251 long long written =
stream()->
write(next_out, have);
276 Log::print(
Say(
"Performance warning: GZipCodec::seek() requested for file %s. For maximum performances avoid seeking a GZipCodec, especially avoid seeking backwards.\n") <<
path() );
281 unsigned char buffer[CHUNK_SIZE];
282 long long remained = pos -
position();
283 long long eat_bytes = remained < CHUNK_SIZE ? remained : CHUNK_SIZE;
284 while ( (remained -=
read(buffer, eat_bytes)) )
285 eat_bytes = remained < CHUNK_SIZE ? remained : CHUNK_SIZE;
290 Log::error(
"GZStream: seek supported only by OM_ReadOnly open mode.\n");
318 ret = inflate(
mZStream, Z_NO_FLUSH);
326 Log::error(
"GZStream: error reading gzip stream.\n");
329 have = CHUNK_SIZE -
mZStream->avail_out;
388 double unco = (double)
size();
389 return float(comp/unco);
long long read(void *buffer, long long byte_count)
Reads byte_count bytes from a file. Returns the number of bytes actually read.
int mUncompressedBufferPtr
virtual long long write_Implementation(const void *buffer, long long byte_count)
long long compressedSize() const
Returns the size of the compressed stream as returned by stream()->size().
An abstract class representing a file.
virtual long long size() const
Returns the uncompressed size of the stream. This is not a thread safe function.
A simple String formatting class.
virtual bool open(EOpenMode mode)
Opens a compressed stream.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
bool seekSet_Implementation(long long pos)
bool fillUncompressedBuffer()
void setStream(VirtualFile *stream)
Installs the VirtualFile representing the GZip file to be read or to be written.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
long long mUncompressedSize
GZipCodec & operator=(const GZipCodec &other)
virtual long long position_Implementation() const
virtual long long read_Implementation(void *buffer, long long bytes_to_read)
GZipCodec(VirtualFile *stream=NULL)
Constructor.
float compressionRatio() const
Returns the compression ratio computed as compressedsize/uncompressedsize.
virtual void close()=0
Closes the file.
virtual void close()
Closes the GZipStream.
const String & path() const
Returns the path of the file.
Visualization Library main namespace.
std::vector< char > mUncompressedBuffer
enum vl::GZipCodec::@0 mMode
static void print(const String &message)
Application message for the user.
The GZipCodec class is a VirtualFile that transparently encodes and decodes a stream of data using th...
long long write(const void *buffer, long long byte_count)
Writes byte_count bytes to a file. Returns the number of bytes actually written.
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
bool seekSet(long long offset)
Changes the current read/write position of a file.
virtual long long size() const =0
Returns the size of the file in bytes.
VLCORE_EXPORT ref< VirtualFile > locateFile(const String &path)
Utility function, equivalent to vl::defFileSystem()->locateFile(path)
void setPath(const String &name)
Changes the path bound to a VirtualFile. Use carefully this function, you shouldn't rename a VirtualF...
unsigned char mZipBufferOut[CHUNK_SIZE]
long long uncompressedSize()
Returns the uncompressed size of the stream.
virtual bool isOpen() const
Returns true if the file is open for read or writing.
unsigned char mZipBufferIn[CHUNK_SIZE]
unsigned int readUInt32(bool little_endian_data=true)
Reads single entry.
The ref<> class is used to reference-count an Object.
bool seekEnd(long long offset)
Changes the current read/write position of a file.
virtual ref< VirtualFile > clone() const
Returns an equivalent GZipCodec.
ref< VirtualFile > mStream
long long position() const
Returns the current position in the file.
int compressionLevel() const
const VirtualFile * stream() const
Returns the VirtualFile representing the GZip file to be read or to be written.