Visit Mozilla.org

nsIFileProtocolHandler

From MDC

The nsIFileProtocolHandler interface provides methods to convert between nsIFile and nsIURI. It also provides access to internet shortcuts stored on the host OS file system.

Contents

nsIFileProtocolHandler is defined in netwerk/protocol/file/public/nsIFileProtocolHandler.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.8).

Inherits from: nsIProtocolHandler

[edit] Method overview

nsIURI newFileURI(in nsIFile aFile);
AUTF8String getURLSpecFromFile( in nsIFile file )
nsIFile getFileFromURLSpec(in AUTF8String url);
nsIURI readURLFile(in nsIFile file);

[edit] Methods

[edit] newFileURI()

This method constructs a new file URI.

 nsIURI newFileURI(in nsIFile aFile);
[edit] Parameters
aFile
The nsIFile to convert.
[edit] Return
A reference to a new nsIURI object.

[edit] getURLSpecFromFile()

Converts the nsIFile to the corresponding URL string. If the nsIFile is a local file, then the result will be a file:// URL string. The resulting string may contain URL-escaped characters.

Note: Under some platforms this is a lossy conversion (e.g., Mac Carbon build).
 AUTF8String getURLSpecFromFile(in nsIFile file);
[edit] Parameters
file
The nsIFile to convert.
[edit] Return
Corresponding url string. The resulting string may contain URL-escaped characters.

[edit] getFileFromURLSpec()

Converts the URL string into the corresponding nsIFile if possible. A local file will be created if the URL string begins with file://.

 nsIFile getFileFromURLSpec(in AUTF8String url);
[edit] Parameters
url
The url string to convert.
[edit] Return
A reference to a new nsIFile object.

[edit] readURLFile()

Takes a local file and tries to interpret it as an internet shortcut (e.g. .url files on windows).

 nsIURI readURLFile(in nsIFile file);
[edit] Parameters
file
The nsIFile to read.
[edit] Return
The nsIURI the file refers to
[edit] Exceptions thrown
NS_ERROR_NOT_AVAILABLE
The OS does not support such files.
NS_ERROR_NOT_AVAILABLE
The file is not an internet shortcut.

[edit] See also

Code_snippets:File_I/O