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

AttributeTypeDescription
exists Read onlyBooleanIndicates 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 onlystringThe path of the target file.
partFilePath Read onlystringThe 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 onlyNumber

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:93 次

字数:4695

最后编辑:6 年前

编辑次数:0 次

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文