32 VirtualFileHTTP(VirtualFileMountHTTP *mount,
const Filename &local_filename,
33 bool implicit_pz_file,
int open_flags) :
35 _local_filename(local_filename),
36 _implicit_pz_file(implicit_pz_file),
37 _status_only(open_flags != 0)
39 URLSpec url(_mount->get_root());
40 url.
set_path(_mount->get_root().get_path() + _local_filename.c_str());
41 _channel = _mount->get_channel();
43 _channel->get_header(url);
45 _channel->get_document(url);
56 _mount->recycle_channel(_channel);
63 get_file_system()
const {
64 return _mount->get_file_system();
71 get_filename()
const {
72 string mount_point = _mount->get_mount_point();
73 if (_local_filename.empty()) {
74 if (mount_point.empty()) {
77 return string(
"/") + mount_point;
81 if (mount_point.empty()) {
84 return string(
"/") + mount_point + string(
"/") + _local_filename.get_fullpath();
92 bool VirtualFileHTTP::
94 return _channel->is_valid();
101 bool VirtualFileHTTP::
102 is_directory()
const {
110 bool VirtualFileHTTP::
111 is_regular_file()
const {
112 return _channel->is_valid();
125 istream *VirtualFileHTTP::
126 open_read_file(
bool auto_unwrap)
const {
135 if (!fetch_file(strstream)) {
140 return return_file(strstream, auto_unwrap);
151 bool VirtualFileHTTP::
152 fetch_file(ostream *buffer_stream)
const {
153 _channel->download_to_stream(buffer_stream,
false);
154 if (!_channel->is_download_complete()) {
157 URLSpec url(_mount->get_root());
158 url.
set_path(_mount->get_root().get_path() + _local_filename.c_str());
160 size_t bytes_downloaded = _channel->get_bytes_downloaded();
161 size_t last_byte = bytes_downloaded;
163 while (bytes_downloaded > 0 && !_channel->is_download_complete()) {
164 _channel->get_subdocument(url, last_byte, 0);
165 _channel->download_to_stream(buffer_stream,
true);
166 bytes_downloaded = _channel->get_bytes_downloaded();
167 last_byte = _channel->get_last_byte_delivered();
171 return _channel->is_download_complete() && _channel->is_valid();
178 istream *VirtualFileHTTP::
179 return_file(istream *buffer_stream,
bool auto_unwrap)
const {
181 bool do_unwrap = (_implicit_pz_file || (auto_unwrap && _local_filename.get_extension() ==
"pz"));
183 istream *result = buffer_stream;
185 if (result !=
nullptr && do_unwrap) {
187 IDecompressStream *wrapper =
new IDecompressStream(result,
true);
202 bool VirtualFileHTTP::
203 was_read_successful()
const {
204 return _channel->is_valid() && _channel->is_download_complete();
212 std::streamsize VirtualFileHTTP::
213 get_file_size(istream *stream)
const {
214 return _channel->get_file_size();
221 std::streamsize VirtualFileHTTP::
222 get_file_size()
const {
223 return _channel->get_file_size();
236 time_t VirtualFileHTTP::
237 get_timestamp()
const {
238 const DocumentSpec &spec = _channel->get_document_spec();
245 #endif // HAVE_OPENSSL 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.
A container for a URL, e.g.
A hierarchy of directories and files that appears to be one continuous file system,...
get_date
Returns the last-modified date associated with the DocumentSpec, if there is one.
The name of a file, such as a texture file or an Egg file.
set_path
Replaces the path part of the URL specification.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
has_date
Returns true if a last-modified date is associated with the DocumentSpec.
A descriptor that refers to a particular version of a document.
TypeHandle is the identifier used to differentiate C++ class types.
A bi-directional stream object that reads and writes data to an internal buffer, which can be retriev...