26 using std::streamsize;
37 _filename = _file->get_filename();
44 if (_vfile ==
nullptr) {
48 _timestamp = _vfile->get_timestamp();
49 _in = _vfile->open_read_file(
true);
50 _owns_in = (_in !=
nullptr);
51 return _owns_in && !_in->fail();
68 if (!filename.empty()) {
93 _read_first_datagram =
false;
105 nassertr(!_read_first_datagram,
false);
106 nassertr(_in !=
nullptr,
false);
108 char *buffer = (
char *)alloca(num_bytes);
109 nassertr(buffer !=
nullptr,
false);
111 _in->read(buffer, num_bytes);
116 header = std::string(buffer, num_bytes);
127 nassertr(_in !=
nullptr,
false);
128 _read_first_datagram =
true;
137 if (num_bytes_32 == 0) {
148 size_t num_bytes = (size_t)num_bytes_32;
149 if (num_bytes_32 == (uint32_t)-1) {
158 if (num_bytes_64 == 0) {
167 num_bytes = (size_t)num_bytes_64;
170 if (num_bytes_64 != (uint64_t)num_bytes) {
181 size_t bytes_read = 0;
182 while (bytes_read < num_bytes) {
183 size_t bytes_left = num_bytes - bytes_read;
194 bytes_left = std::min(bytes_left, (
size_t)4*1024*1024);
196 PTA_uchar buffer = data.modify_array();
197 buffer.resize(buffer.size() + bytes_left);
198 unsigned char *ptr = &buffer.p()[bytes_read];
200 _in->read((
char *)ptr, (streamsize)bytes_left);
206 bytes_read += bytes_left;
225 nassertr(_in !=
nullptr,
false);
226 _read_first_datagram =
true;
231 if (_in->fail() || (_in->eof() && num_bytes_32 > 0)) {
235 streamsize num_bytes = (streamsize)num_bytes_32;
236 if (num_bytes_32 == (uint32_t)-1) {
243 if (_file !=
nullptr) {
244 info =
SubfileInfo(_file, _in->tellg(), num_bytes);
245 _in->seekg(num_bytes, std::ios::cur);
252 Filename filename = tfile->get_filename();
256 <<
"Couldn't write to " << tfile->get_filename() <<
"\n";
260 if (util_cat.is_debug()) {
262 <<
"Copying " << num_bytes <<
" bytes to " << tfile->get_filename() <<
"\n";
265 streamsize num_remaining = num_bytes;
266 static const size_t buffer_size = 4096;
267 char buffer[buffer_size];
269 _in->read(buffer, std::min((streamsize)buffer_size, num_remaining));
270 streamsize count = _in->gcount();
272 out.write(buffer, count);
275 <<
"Couldn't write " << num_bytes <<
" bytes to " 276 << tfile->get_filename() <<
"\n";
279 num_remaining -= count;
280 if (num_remaining == 0) {
283 _in->read(buffer, std::min((streamsize)buffer_size, num_remaining));
284 count = _in->gcount();
287 if (num_remaining != 0) {
289 <<
"Truncated data stream.\n";
303 return _in !=
nullptr ? _in->eof() :
true;
311 if (_in ==
nullptr) {
367 if (_in ==
nullptr) {
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
Keeps a reference-counted pointer to a file on disk.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A hierarchy of directories and files that appears to be one continuous file system,...
void set_binary()
Indicates that the filename represents a binary file.
uint64_t get_uint64()
Extracts an unsigned 64-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
This is a special kind of FileReference class that automatically deletes the file in question when it...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class records a particular byte sub-range within an existing file on disk.
static Filename temporary(const std::string &dirname, const std::string &prefix, const std::string &suffix=std::string(), Type type=T_general)
Generates a temporary filename within the indicated directory, using the indicated prefix.
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 ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.