15 #include "datagramInputFile.h" 16 #include "temporaryFile.h" 17 #include "numeric_types.h" 18 #include "datagramIterator.h" 19 #include "profileTimer.h" 20 #include "config_util.h" 21 #include "config_express.h" 22 #include "virtualFileSystem.h" 23 #include "streamReader.h" 37 _filename = _file->get_filename();
48 _timestamp = _vfile->get_timestamp();
49 _in = _vfile->open_read_file(
true);
50 _owns_in = (_in != (istream *)NULL);
51 return _owns_in && !_in->fail();
72 if (!filename.empty()) {
92 _in = (istream *)NULL;
99 _read_first_datagram =
false;
114 nassertr(!_read_first_datagram,
false);
115 nassertr(_in != (istream *)NULL,
false);
117 char *buffer = (
char *)alloca(num_bytes);
118 nassertr(buffer != (
char *)NULL,
false);
120 _in->read(buffer, num_bytes);
121 if (_in->fail() || _in->eof()) {
125 header = string(buffer, num_bytes);
139 nassertr(_in != (istream *)NULL,
false);
140 _read_first_datagram =
true;
145 if (_in->fail() || _in->eof()) {
149 if (num_bytes_32 == 0) {
156 streamsize num_bytes = (streamsize)num_bytes_32;
157 if (num_bytes_32 == (PN_uint32)-1) {
164 nassertr(num_bytes == (
size_t)num_bytes,
false);
171 if (num_bytes > 65536) {
172 char *buffer = (
char *)PANDA_MALLOC_ARRAY(num_bytes);
173 nassertr(buffer != (
char *)NULL,
false);
175 _in->read(buffer, num_bytes);
176 if (_in->fail() || _in->eof()) {
178 PANDA_FREE_ARRAY(buffer);
183 PANDA_FREE_ARRAY(buffer);
186 char *buffer = (
char *)alloca(num_bytes);
187 nassertr(buffer != (
char *)NULL,
false);
189 _in->read(buffer, num_bytes);
190 if (_in->fail() || _in->eof()) {
217 nassertr(_in != (istream *)NULL,
false);
218 _read_first_datagram =
true;
223 if (_in->fail() || _in->eof()) {
227 streamsize num_bytes = (streamsize)num_bytes_32;
228 if (num_bytes_32 == (PN_uint32)-1) {
236 info =
SubfileInfo(_file, _in->tellg(), num_bytes);
237 _in->seekg(num_bytes, ios::cur);
244 Filename filename = tfile->get_filename();
248 <<
"Couldn't write to " << tfile->get_filename() <<
"\n";
252 if (util_cat.is_debug()) {
254 <<
"Copying " << num_bytes <<
" bytes to " << tfile->get_filename() <<
"\n";
257 streamsize num_remaining = num_bytes;
258 static const size_t buffer_size = 4096;
259 char buffer[buffer_size];
261 _in->read(buffer, min((streamsize)buffer_size, num_remaining));
262 streamsize count = _in->gcount();
264 out.write(buffer, count);
267 <<
"Couldn't write " << num_bytes <<
" bytes to " 268 << tfile->get_filename() <<
"\n";
271 num_remaining -= count;
272 if (num_remaining == 0) {
275 _in->read(buffer, min((streamsize)buffer_size, num_remaining));
276 count = _in->gcount();
279 if (num_remaining != 0) {
281 <<
"Truncated data stream.\n";
298 return _in != (istream *)NULL ? _in->eof() :
true;
309 if (_in == (istream *)NULL) {
381 if (_in == (istream *)NULL) {
Keeps a reference-counted pointer to a file on disk.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
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.
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
static void consider_yield()
Possibly suspends the current thread for the rest of the current epoch, if it has run for enough this...
The abstract base class for a file or directory within the VirtualFileSystem.
static void close_read_file(istream *stream)
Closes a file opened by a previous call to open_read_file().
static Filename temporary(const string &dirname, const string &prefix, const string &suffix=string(), Type type=T_general)
Generates a temporary filename within the indicated directory, using the indicated prefix...
PN_uint64 get_uint64()
Extracts an unsigned 64-bit integer.
This is a special kind of FileReference class that automatically deletes the file in question when it...
The name of a file, such as a texture file or an Egg file.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
This class records a particular byte sub-range within an existing file on disk.
A class to read sequential binary data directly from an istream.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...