32 _filename = _file->get_filename();
39 if (_vfile ==
nullptr) {
43 _out = _vfile->open_write_file(
true,
true);
44 _owns_out = (_out !=
nullptr);
45 return _owns_out && !_out->fail();
61 if (!filename.empty()) {
85 _wrote_first_datagram =
false;
97 nassertr(_out !=
nullptr,
false);
98 nassertr(!_wrote_first_datagram,
false);
100 _out->write((
const char *)&header[0], header.size());
101 thread_consider_yield();
102 return !_out->fail();
113 nassertr(_out !=
nullptr,
false);
114 nassertr(!_wrote_first_datagram,
false);
116 _out->write(header.data(), header.size());
117 thread_consider_yield();
118 return !_out->fail();
127 nassertr(_out !=
nullptr,
false);
128 _wrote_first_datagram =
true;
132 size_t num_bytes = data.get_length();
133 if (num_bytes == (uint32_t)-1 || num_bytes != (uint32_t)num_bytes) {
143 _out->write((
const char *)data.get_data(), data.get_length());
144 thread_consider_yield();
146 return !_out->fail();
160 nassertr(_out !=
nullptr,
false);
161 _wrote_first_datagram =
true;
165 if (vfile ==
nullptr) {
168 std::istream *in = vfile->open_read_file(
true);
173 streamsize size = vfile->get_file_size(in);
174 streamsize num_remaining = size;
177 if (num_remaining == (uint32_t)-1 || num_remaining != (uint32_t)num_remaining) {
186 static const size_t buffer_size = 4096;
187 char buffer[buffer_size];
189 streampos start = _out->tellp();
190 in->read(buffer, min((streamsize)buffer_size, num_remaining));
191 streamsize count = in->gcount();
193 _out->write(buffer, count);
195 vfile->close_read_file(in);
198 num_remaining -= count;
199 if (num_remaining == 0) {
202 in->read(buffer, min((streamsize)buffer_size, num_remaining));
203 count = in->gcount();
206 vfile->close_read_file(in);
208 if (num_remaining != 0) {
210 <<
"Truncated input stream.\n";
229 nassertr(_out !=
nullptr,
false);
230 _wrote_first_datagram =
true;
237 streamsize num_remaining = source.
get_size();
240 if (num_remaining == (uint32_t)-1 || num_remaining != (uint32_t)num_remaining) {
249 static const size_t buffer_size = 4096;
250 char buffer[buffer_size];
252 streampos start = _out->tellp();
254 in.read(buffer, min((streamsize)buffer_size, num_remaining));
255 streamsize count = in.gcount();
257 _out->write(buffer, count);
261 num_remaining -= count;
262 if (num_remaining == 0) {
265 in.read(buffer, min((streamsize)buffer_size, num_remaining));
269 if (num_remaining != 0) {
271 <<
"Truncated input stream.\n";
284 if (_out ==
nullptr) {
300 if (_out !=
nullptr) {
334 if (_out ==
nullptr) {
337 return _out->tellp();
virtual bool copy_datagram(SubfileInfo &result, const Filename &filename)
Copies the file data from the entire indicated file (via the vfs) as the next datagram.
virtual void flush()
Ensures that all datagrams previously written will be visible in the output file.
bool open(const FileReference *file)
Opens the indicated filename for writing.
bool write_header(const vector_uchar &header)
Writes a sequence of bytes to the beginning of the datagram file.
void close()
Closes the file.
virtual std::streampos get_file_pos()
Returns the current file position within the data stream, if any, or 0 if the file position is not me...
virtual const FileReference * get_file()
Returns the FileReference that provides the target for these datagrams, if any, or NULL if the datagr...
virtual bool is_error()
Returns true if the file has reached an error condition.
virtual const Filename & get_filename()
Returns the filename that provides the target for these datagrams, if any, or empty string if the dat...
virtual bool put_datagram(const Datagram &data)
Writes the given datagram to the file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Keeps a reference-counted pointer to a file on disk.
The name of a file, such as a texture file or an Egg file.
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
void set_binary()
Indicates that the filename represents a binary file.
A StreamWriter object is used to write sequential binary data directly to an ostream.
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the stream.
void add_uint64(uint64_t value)
Adds an unsigned 64-bit integer to the stream.
This class records a particular byte sub-range within an existing file on disk.
const Filename & get_filename() const
A shortcut to the filename.
std::streampos get_start() const
Returns the offset within the file at which this file data begins.
std::streamsize get_size() const
Returns the number of consecutive bytes, beginning at get_start(), that correspond to this file data.
A hierarchy of directories and files that appears to be one continuous file system,...
static void close_write_file(std::ostream *stream)
Closes a file opened by a previous call to open_write_file().
PointerTo< VirtualFile > create_file(const Filename &filename)
Attempts to create a file by the indicated name in the filesystem, if possible, and returns it.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.