The goog.net.FileDownloader Class

goog.net.FileDownloader
> goog.Disposable

goog.net.FileDownloader(dir, opt_pool)

A class for downloading remote files and storing them locally using the HTML5 filesystem API.

dir {!goog.fs.DirectoryEntry}
The directory in which the downloaded files are stored. This directory should be solely managed by FileDownloader.
opt_pool {goog.net.XhrIoPool=}
The pool of XhrIo objects to use for downloading files.

The goog.net.FileDownloader.Error Class

The error object for FileDownloader download errors. … more

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.download(url)

Download a remote file and save its contents to the filesystem. A given file is uniquely identified by its URL string; this means that the relative and absolute URLs for a single file are considered different for the purposes of the FileDownloader. Returns a Deferred that will contain the downloaded blob. If there's an error while downloading the URL, this Deferred will be passed the {@link goog.net.FileDownloader.Error} object as an errback. If a download is already in progress for the given URL, this will return the deferred blob for that download. If the URL has already been downloaded, this will fail once it tries to save the downloaded blob. When a download is in progress, all Deferreds returned for that download will be branches of a single parent. If all such branches are cancelled, or if one is cancelled with opt_deepCancel set, then the download will be cancelled as well.

url {string}
The URL of the file to download.
returns {!goog.async.Deferred}
The deferred result blob.

.getDownloadedBlob(url)

Load a downloaded blob from the filesystem. Will fire a deferred error if the given URL has not yet been downloaded.

url {string}
The URL of the blob to load.
returns {!goog.async.Deferred}
The deferred Blob object. The callback will be passed the blob. If a file API error occurs while loading the blob, that error will be passed to the errback.

.getLocalUrl(url)

Get the local filesystem: URL for a downloaded file. This is different from the blob: URL that's available from getDownloadedBlob(). If the end user accesses the filesystem: URL, the resulting file's name will be determined by the download filename as opposed to an arbitrary GUID. In addition, the filesystem: URL is connected to a filesystem location, so if the download is removed then that URL will become invalid. Warning: in Chrome 12, some filesystem: URLs are opened inline. This means that e.g. HTML pages given to the user via filesystem: URLs will be opened and processed by the browser.

url {string}
The URL of the file to get the URL of.
returns {!goog.async.Deferred}
The deferred filesystem: URL. The callback will be passed the URL. If a file API error occurs while loading the blob, that error will be passed to the errback.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isDownloaded(url)

Return (deferred) whether or not a URL has been downloaded. Will fire a deferred error if something goes wrong when determining this.

url {string}
The URL to check.
returns {!goog.async.Deferred}
The deferred boolean. The callback will be passed the boolean. If a file API error occurs while checking the existence of the downloaded URL, that error will be passed to the errback.

.isDownloading(url)

Returns whether or not there is an active download for a given URL.

url {string}
The URL of the download to check.
returns {boolean}
Whether or not there is an active download for the URL.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.remove(url)

Remove a URL from the FileDownloader. This returns a Deferred. If the removal is completed successfully, its callback will be called without any value. If the removal fails, its errback will be called with the {@link goog.fs.Error}.

url {string}
The URL to remove.
returns {!goog.async.Deferred}
The deferred used for registering callbacks on success or on error.

.setBlob(url, blob, opt_name)

Save a blob for a given URL. This works just as through the blob were downloaded form that URL, except you specify the blob and no HTTP request is made. If the URL is currently being downloaded, it's indeterminate whether the blob being set or the blob being downloaded will end up in the filesystem. Whichever one doesn't get saved will have an error. To ensure that one or the other takes precedence, use {@link #waitForDownload} to allow the download to complete before setting the blob.

url {string}
The URL at which to set the blob.
blob {!Blob}
The blob to set.
opt_name {string=}
The name of the file. If this isn't given, it's determined from the URL.
returns {!goog.async.Deferred}
The deferred used for registering callbacks on success or on error. This can be cancelled just like a {@link #download} Deferred. The objects passed to the errback will be {@link goog.net.FileDownloader.Error}s.

.waitForDownload(url)

Return a Deferred that will fire once no download is active for a given URL. If there's no download active for that URL when this is called, the deferred will fire immediately; otherwise, it will fire once the download is complete, whether or not it succeeds.

url {string}
The URL of the download to wait for.
returns {!goog.async.Deferred}
The Deferred that will fire when the download is complete.