DownloadTarget

A DownloadTarget object represents the target of a download, for example a file in the global downloads directory, or a file in the system temporary directory.

Method overview

Promise refresh()

Properties

Attribute Type Description
exists Read only Requires Gecko 38 Boolean Indicates whether or not the target file exists. This is a dynamic property, which is updated when the download is completed or when the Download.refresh() method is called. You can use this instead of using file system calls to check for the existence of the file in order to reduce IO overhead.
path Read only string The path of the target file.
partFilePath Read only string The path of the ".part" file containing the data downloaded so far, or null to disable the use of a ".part" file to keep partially downloaded data.
size Read only Requires Gecko 38 Number

The size of the target file, in bytes, or zero if the download has not yet been completed.

It is possible for this property to have a non-zero value even if the target file no longer exists, if the value is available in download metadata. If that metadata is no longer available and the file has been deleted, then this value is zero.

For single-file downloads, this property's value will always match the actual size of the file on disk, while the Download.totalBytes property, when available, may indicate the size of the data as encoded for transfer instead.

For downloads of multiple files, such as downloading a web page and its required media to disk, the meaning of this property is undefined. It currently indicates the size of the main file (such as the HTML document) rather than the sum of all of the files' sizes, but you must not rely upon this behavior, as it is subject to change.

This is a dynamic property, which is updated when the download finishes or whenever the Download.refresh() method is called. You can use this value from the front-end to reduce file I/O that would be required to check the file directly.

Methods

refresh()

Updates the state of a finished, failed, or canceled download based on the current state as indicated by the file system. If the download is in progress or has been finalized, this method does nothing and returns a resolved Promise.

Calling this method lets the Download object's properties be updated if the user moves or deletes the target file or its associated ".part" file, which contains a partially-downloaded file's contents.

Promise refresh();
Parameters

None.

Promise resolves to

undefined when the state of the download has been updated.

Promise can be rejected with

Never.

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, P.A.
 Last updated by: Sheppy,