15 #include "compress_string.h"
19 #include "virtualFileSystem.h"
20 #include "config_express.h"
30 compress_string(
const string &source,
int compression_level) {
34 OCompressStream compress;
35 compress.open(&dest,
false, compression_level);
36 compress.write(source.data(), source.length());
38 if (compress.fail()) {
57 decompress_string(
const string &source) {
61 if (!decompress_stream(source_stream, dest_stream)) {
65 return dest_stream.str();
78 EXPCL_PANDAEXPRESS
bool
79 compress_file(
const Filename &source,
const Filename &dest,
int compression_level) {
86 istream *source_stream = vfs->
open_read_file(source_filename,
false);
87 if (source_stream == NULL) {
88 express_cat.info() <<
"Couldn't open file " << source_filename <<
"\n";
92 Filename dest_filename = Filename::binary_filename(dest);
93 ostream *dest_stream = vfs->
open_write_file(dest_filename,
false,
true);
94 if (dest_stream == NULL) {
95 express_cat.info() <<
"Couldn't open file " << dest_filename <<
"\n";
100 bool result = compress_stream(*source_stream, *dest_stream, compression_level);
119 EXPCL_PANDAEXPRESS
bool
121 Filename source_filename = Filename::binary_filename(source);
123 istream *source_stream = vfs->
open_read_file(source_filename,
false);
124 if (source_stream == NULL) {
125 express_cat.info() <<
"Couldn't open file " << source_filename <<
"\n";
134 ostream *dest_stream = vfs->
open_write_file(dest_filename,
false,
true);
135 if (dest_stream == NULL) {
136 express_cat.info() <<
"Couldn't open file " << dest_filename <<
"\n";
141 bool result = decompress_stream(*source_stream, *dest_stream);
158 compress_stream(istream &source, ostream &dest,
int compression_level) {
159 OCompressStream compress;
160 compress.open(&dest,
false, compression_level);
162 static const size_t buffer_size = 4096;
163 char buffer[buffer_size];
165 source.read(buffer, buffer_size);
166 size_t count = source.gcount();
168 compress.write(buffer, count);
169 source.read(buffer, buffer_size);
170 count = source.gcount();
174 return (!source.fail() || source.eof()) && (!compress.fail());
192 decompress_stream(istream &source, ostream &dest) {
193 IDecompressStream decompress(&source,
false);
195 static const size_t buffer_size = 4096;
196 char buffer[buffer_size];
198 decompress.read(buffer, buffer_size);
199 size_t count = decompress.gcount();
201 dest.write(buffer, count);
202 decompress.read(buffer, buffer_size);
203 count = decompress.gcount();
206 return (!decompress.fail() || decompress.eof()) && (!dest.fail());
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
void set_binary()
Indicates that the filename represents a binary file.
static void close_read_file(istream *stream)
Closes a file opened by a previous call to open_read_file().
The name of a file, such as a texture file or an Egg file.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read...
ostream * open_write_file(const Filename &filename, bool auto_wrap, bool truncate)
Convenience function; returns a newly allocated ostream if the file exists and can be written...
static void close_write_file(ostream *stream)
Closes a file opened by a previous call to open_write_file().
bool is_binary_or_text() const
Returns true either is_binary() or is_text() is true; that is, that the filename has been specified a...