38 _decompress =
nullptr;
56 initiate(
const Filename &source_file) {
58 if (extension ==
"pz" || extension ==
"gz") {
61 return initiate(source_file, dest_file);
64 if (downloader_cat.is_debug()) {
65 downloader_cat.debug()
66 <<
"Unknown file extension for decompressor: ." 67 << extension << std::endl;
69 return EU_error_abort;
81 _source_filename =
Filename(source_file);
82 _source_filename.set_binary();
84 pifstream *source_pfstream =
new pifstream;
85 _source = source_pfstream;
86 if (!_source_filename.open_read(*source_pfstream)) {
87 downloader_cat.error()
88 <<
"Unable to read " << _source_filename <<
"\n";
89 return get_write_error();
93 source_pfstream->seekg(0, std::ios::end);
94 _source_length = source_pfstream->tellg();
95 if (_source_length == 0) {
96 downloader_cat.warning()
97 <<
"Zero length file: " << source_file <<
"\n";
98 return EU_error_file_empty;
100 source_pfstream->seekg(0, std::ios::beg);
104 dest_filename.set_binary();
106 pofstream *dest_pfstream =
new pofstream;
107 _dest = dest_pfstream;
108 if (dest_filename.exists()) {
109 downloader_cat.info()
110 << dest_filename <<
" already exists, removing.\n";
111 if (!dest_filename.unlink()) {
112 downloader_cat.error()
113 <<
"Unable to remove old " << dest_filename <<
"\n";
114 return get_write_error();
117 if (downloader_cat.is_debug()) {
118 downloader_cat.debug()
119 << dest_filename <<
" does not already exist.\n";
122 if (!dest_filename.open_write(*dest_pfstream,
true)) {
123 downloader_cat.error()
124 <<
"Unable to write to " << dest_filename <<
"\n";
125 return get_write_error();
129 _decompress =
new IDecompressStream(_source,
false);
140 if (_decompress ==
nullptr) {
146 double now = clock->get_short_time();
147 double finish = now + decompressor_step_time;
149 static const size_t buffer_size = 1024;
150 char buffer[buffer_size];
152 _decompress->read(buffer, buffer_size);
153 size_t count = _decompress->gcount();
155 _dest->write(buffer, count);
157 now = clock->get_short_time();
163 _decompress->read(buffer, buffer_size);
164 count = _decompress->gcount();
169 if (!keep_temporary_files) {
170 _source_filename.unlink();
180 decompress(
const Filename &source_file) {
181 int ret = initiate(source_file);
185 int ch = _decompress->get();
186 while (ch != EOF && !_decompress->fail()) {
188 ch = _decompress->get();
192 if (!keep_temporary_files) {
193 _source_filename.unlink();
203 decompress(
Ramfile &source_and_dest_file) {
204 std::istringstream source(source_and_dest_file._data);
205 std::ostringstream dest;
207 IDecompressStream decompress(&source,
false);
209 int ch = decompress.get();
210 while (ch != EOF && !decompress.fail()) {
212 ch = decompress.get();
215 source_and_dest_file._pos = 0;
216 source_and_dest_file._data = dest.str();
223 PN_stdfloat Decompressor::
224 get_progress()
const {
225 if (_decompress ==
nullptr) {
230 nassertr(_source_length > 0, 0.0);
231 size_t source_pos = _source->tellg();
235 return (0.99f * (PN_stdfloat)source_pos / (PN_stdfloat)_source_length);
243 if (_source !=
nullptr) {
247 if (_dest !=
nullptr) {
251 if (_decompress !=
nullptr) {
253 _decompress =
nullptr;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static TrueClock * get_global_ptr()
Returns a pointer to the one TrueClock object in the world.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An in-memory buffer specifically designed for downloading files to memory.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An interface to whatever real-time clock we might have available in the current environment.
std::string get_extension() const
Returns the file extension.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.