15 #include "virtualFileHTTP.h"
16 #include "virtualFileMountHTTP.h"
17 #include "stringStream.h"
31 VirtualFileHTTP(VirtualFileMountHTTP *mount,
const Filename &local_filename,
32 bool implicit_pz_file,
int open_flags) :
34 _local_filename(local_filename),
35 _implicit_pz_file(implicit_pz_file),
36 _status_only(open_flags != 0)
38 URLSpec url(_mount->get_root());
39 url.
set_path(_mount->get_root().get_path() + _local_filename.c_str());
40 _channel = _mount->get_channel();
42 _channel->get_header(url);
44 _channel->get_document(url);
57 _mount->recycle_channel(_channel);
67 get_file_system()
const {
68 return _mount->get_file_system();
78 get_filename()
const {
79 string mount_point = _mount->get_mount_point();
80 if (_local_filename.empty()) {
81 if (mount_point.empty()) {
84 return string(
"/") + mount_point;
88 if (mount_point.empty()) {
91 return string(
"/") + mount_point + string(
"/") + _local_filename.get_fullpath();
101 bool VirtualFileHTTP::
103 return _channel->is_valid();
112 bool VirtualFileHTTP::
113 is_directory()
const {
123 bool VirtualFileHTTP::
124 is_regular_file()
const {
125 return _channel->is_valid();
142 istream *VirtualFileHTTP::
143 open_read_file(
bool auto_unwrap)
const {
152 if (!fetch_file(strstream)) {
157 return return_file(strstream, auto_unwrap);
172 bool VirtualFileHTTP::
173 fetch_file(ostream *buffer_stream)
const {
174 _channel->download_to_stream(buffer_stream,
false);
175 if (!_channel->is_download_complete()) {
178 URLSpec url(_mount->get_root());
179 url.
set_path(_mount->get_root().get_path() + _local_filename.c_str());
181 size_t bytes_downloaded = _channel->get_bytes_downloaded();
182 size_t last_byte = bytes_downloaded;
184 while (bytes_downloaded > 0 && !_channel->is_download_complete()) {
185 _channel->get_subdocument(url, last_byte, 0);
186 _channel->download_to_stream(buffer_stream,
true);
187 bytes_downloaded = _channel->get_bytes_downloaded();
188 last_byte = _channel->get_last_byte_delivered();
192 return _channel->is_download_complete() && _channel->is_valid();
202 istream *VirtualFileHTTP::
203 return_file(istream *buffer_stream,
bool auto_unwrap)
const {
205 bool do_unwrap = (_implicit_pz_file || (auto_unwrap && _local_filename.get_extension() ==
"pz"));
207 istream *result = buffer_stream;
209 if (result != (istream *)NULL && do_unwrap) {
211 IDecompressStream *wrapper =
new IDecompressStream(result,
true);
229 bool VirtualFileHTTP::
230 was_read_successful()
const {
231 return _channel->is_valid() && _channel->is_download_complete();
243 streamsize VirtualFileHTTP::
244 get_file_size(istream *stream)
const {
245 return _channel->get_file_size();
254 streamsize VirtualFileHTTP::
255 get_file_size()
const {
256 return _channel->get_file_size();
273 time_t VirtualFileHTTP::
274 get_timestamp()
const {
275 const DocumentSpec &spec = _channel->get_document_spec();
282 #endif // HAVE_OPENSSL
const HTTPDate & get_date() const
Returns the last-modified date associated with the DocumentSpec, if there is one. ...
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
A container for a URL, e.g.
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.
time_t get_time() const
Returns the date as a C time_t value.
bool has_date() const
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.
A descriptor that refers to a particular version of a document.
TypeHandle is the identifier used to differentiate C++ class types.
void set_path(const string &path)
Replaces the path part of the URL specification.
A bi-directional stream object that reads and writes data to an internal buffer, which can be retriev...