35VirtualFileHTTP(VirtualFileMountHTTP *mount,
const Filename &local_filename,
36 bool implicit_pz_file,
int open_flags) :
38 _local_filename(local_filename),
39 _implicit_pz_file(implicit_pz_file),
40 _status_only(open_flags != 0)
42 URLSpec url(_mount->get_root());
43 url.set_path(_mount->get_root().get_path() + _local_filename.c_str());
44 _channel = _mount->get_channel();
46 _channel->get_header(url);
48 _channel->get_document(url);
59 _mount->recycle_channel(_channel);
66get_file_system()
const {
67 return _mount->get_file_system();
75 string mount_point = _mount->get_mount_point();
76 if (_local_filename.empty()) {
77 if (mount_point.empty()) {
80 return string(
"/") + mount_point;
84 if (mount_point.empty()) {
87 return string(
"/") + mount_point + string(
"/") + _local_filename.get_fullpath();
97 return _channel->is_valid();
104bool VirtualFileHTTP::
105is_directory()
const {
113bool VirtualFileHTTP::
114is_regular_file()
const {
115 return _channel->is_valid();
128istream *VirtualFileHTTP::
129open_read_file(
bool auto_unwrap)
const {
138 if (!fetch_file(strstream)) {
143 return return_file(strstream, auto_unwrap);
150bool VirtualFileHTTP::
151read_file(vector_uchar &result,
bool auto_unwrap)
const {
157 if (!_channel->download_to_ram(&ramfile,
false)) {
161 const string &data = ramfile.
get_data();
162 std::copy(data.begin(), data.end(), std::back_inserter(result));
174bool VirtualFileHTTP::
175fetch_file(ostream *buffer_stream)
const {
176 _channel->download_to_stream(buffer_stream,
false);
177 if (!_channel->is_download_complete()) {
180 URLSpec url(_mount->get_root());
181 url.set_path(_mount->get_root().get_path() + _local_filename.c_str());
183 size_t bytes_downloaded = _channel->get_bytes_downloaded();
184 size_t last_byte = bytes_downloaded;
186 while (bytes_downloaded > 0 && !_channel->is_download_complete()) {
187 _channel->get_subdocument(url, last_byte, 0);
188 _channel->download_to_stream(buffer_stream,
true);
189 bytes_downloaded = _channel->get_bytes_downloaded();
190 last_byte = _channel->get_last_byte_delivered();
194 return _channel->is_download_complete() && _channel->is_valid();
201istream *VirtualFileHTTP::
202return_file(istream *buffer_stream,
bool auto_unwrap)
const {
204 bool do_unwrap = (_implicit_pz_file || (auto_unwrap && _local_filename.get_extension() ==
"pz"));
206 istream *result = buffer_stream;
208 if (result !=
nullptr && do_unwrap) {
210 IDecompressStream *wrapper =
new IDecompressStream(result,
true);
225bool VirtualFileHTTP::
226was_read_successful()
const {
227 return _channel->is_valid() && _channel->is_download_complete();
235std::streamsize VirtualFileHTTP::
236get_file_size(istream *stream)
const {
237 return _channel->get_file_size();
244std::streamsize VirtualFileHTTP::
245get_file_size()
const {
246 return _channel->get_file_size();
259time_t VirtualFileHTTP::
260get_timestamp()
const {
261 const DocumentSpec &spec = _channel->get_document_spec();
A descriptor that refers to a particular version of a document.
get_date
Returns the last-modified date associated with the DocumentSpec, if there is one.
has_date
Returns true if a last-modified date is associated with the DocumentSpec.
The name of a file, such as a texture file or an Egg file.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
An in-memory buffer specifically designed for downloading files to memory.
const std::string & get_data() const
Returns the entire buffer contents as a string, regardless of the current data pointer.
A bi-directional stream object that reads and writes data to an internal buffer, which can be retriev...
TypeHandle is the identifier used to differentiate C++ class types.
A container for a URL, e.g.
A hierarchy of directories and files that appears to be one continuous file system,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.