VirtualFile

class VirtualFile

Bases: TypedReferenceCount

The abstract base class for a file or directory within the VirtualFileSystem.

Inheritance diagram

Inheritance diagram of VirtualFile

virtual void close_read_file(std::istream *stream) const

Closes a file opened by a previous call to open_read_file(). This really just deletes the istream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.

virtual void close_read_write_file(std::iostream *stream)

Closes a file opened by a previous call to open_read_write_file(). This really just deletes the iostream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.

virtual void close_write_file(std::ostream *stream)

Closes a file opened by a previous call to open_write_file(). This really just deletes the ostream pointer, but it is recommended to use this interface instead of deleting it explicitly, to help work around compiler issues.

virtual bool copy_file(VirtualFile *new_file)

Attempts to copy the contents of this file to the indicated file. Returns true on success, false on failure.

virtual bool delete_file(void)

Attempts to delete this file or directory. This can remove a single file or an empty directory. It will not remove a nonempty directory. Returns true on success, false on failure.

static TypeHandle get_class_type(void)
virtual std::streamsize get_file_size(std::istream *stream) const
virtual std::streamsize get_file_size(void) const

Returns the current size on disk (or wherever it is) of the already-open file. Pass in the stream that was returned by open_read_file(); some implementations may require this stream to determine the size.

Returns the current size on disk (or wherever it is) of the file before it has been opened.

virtual VirtualFileSystem *get_file_system(void) const = 0
virtual Filename get_filename(void) const = 0
Filename const &get_original_filename(void) const

Returns the original filename as it was used to locate this VirtualFile. This is usually, but not always, the same string returned by get_filename().

virtual bool get_system_info(SubfileInfo &info)

Populates the SubfileInfo structure with the data representing where the file actually resides on disk, if this is knowable. Returns true if the file might reside on disk, and the info is populated, or false if it does not (or it is not known where the file resides), in which case the info is meaningless.

virtual time_t get_timestamp(void) const

Returns a time_t value that represents the time the file was last modified, to within whatever precision the operating system records this information (on a Windows95 system, for instance, this may only be accurate to within 2 seconds).

If the timestamp cannot be determined, either because it is not supported by the operating system or because there is some error (such as file not found), returns 0.

virtual bool has_file(void) const

Returns true if this file exists, false otherwise.

virtual bool is_directory(void) const

Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.

virtual bool is_regular_file(void) const

Returns true if this file represents a regular file (and read_file() may be called), false otherwise.

virtual bool is_writable(void) const

Returns true if this file may be written to, which implies write_file() may be called (unless it is a directory instead of a regular file).

void ls(std::ostream &out = ::std::cout) const

If the file represents a directory, lists its contents.

void ls_all(std::ostream &out = ::std::cout) const

If the file represents a directory, recursively lists its contents and those of all subdirectories.

virtual std::ostream *open_append_file(void)

Works like open_write_file(), but the file is opened in append mode. Like open_write_file(), the returned pointer should eventually be passed to close_write_file().

virtual std::iostream *open_read_append_file(void)

Works like open_read_write_file(), but the file is opened in append mode. Like open_read_write_file(), the returned pointer should eventually be passed to close_read_write_file().

virtual std::istream *open_read_file(bool auto_unwrap) const

Opens the file for reading. Returns a newly allocated istream on success (which you should eventually delete when you are done reading). Returns NULL on failure.

virtual std::iostream *open_read_write_file(bool truncate)

Opens the file for writing. Returns a newly allocated iostream on success (which you should eventually delete when you are done writing). Returns NULL on failure.

virtual std::ostream *open_write_file(bool auto_wrap, bool truncate)

Opens the file for writing. Returns a newly allocated ostream on success (which you should eventually delete when you are done writing). Returns NULL on failure.

void output(std::ostream &out) const
PyObject *read_file(bool auto_unwrap) const

Returns the entire contents of the file as a string.

Fills up the indicated string with the contents of the file, if it is a regular file. Returns true on success, false otherwise.

Fills up the indicated pvector with the contents of the file, if it is a regular file. Returns true on success, false otherwise.

virtual bool rename_file(VirtualFile *new_file)

Attempts to move or rename this file or directory. If the original file is an ordinary file, it will quietly replace any already-existing file in the new filename (but not a directory). If the original file is a directory, the new filename must not already exist.

If the file is a directory, the new filename must be within the same mount point. If the file is an ordinary file, the new filename may be anywhere; but if it is not within the same mount point then the rename operation is automatically performed as a two-step copy-and-delete operation.

PointerTo<VirtualFileList> scan_directory(void) const

If the file represents a directory (that is, is_directory() returns true), this returns the list of files within the directory at the current time. Returns NULL if the file is not a directory or if the directory cannot be read.

virtual bool was_read_successful(void) const

Call this method after a reading the istream returned by open_read_file() to completion. If it returns true, the file was read completely and without error; if it returns false, there may have been some errors or a truncated file read. This is particularly likely if the stream is a VirtualFileHTTP.

PyObject *write_file(PyObject *data, bool auto_wrap)

Writes the entire contents of the file as a string, if it is writable.

Writes the indicated data to the file, if it is writable. Returns true on success, false otherwise.