> For the complete documentation index, see [llms.txt](https://krypt0nn.gitbook.io/empathize/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krypt0nn.gitbook.io/empathize/api/network-api/downloader.md).

# Downloader

## Stream object

Code examples below

### stream.start(callback)

Specify event that will be called when downloading will be started

### stream.progress(callback)

Specify event that will be called every `stream.progressInterval` ms

This callback will receive the current downloaded data size, total data size, and how much data was downloaded after the previous call

### stream.finish(callback)

Specify event that will be called when downloading will be finished

### stream.pause()

Pause downloading

### stream.resume()

Resume downloading

### stream.close(forced)

Close downloading stream

## Downloader class

### Downloader.download(uri, output)

```typescript
import { Downloader } from '@empathize/framework';

// Second argument will be automatically parsed
// by Downloader.fileFromUri() method if it is not specified
Downloader.download('https://www.youtube.com', 'youtube.html').then(() => {
    stream.progressInterval = 1000;
    
    stream.start(() => {
        console.log('Downloading started');
    });
    
    stream.progress((current, total, difference) => {
        console.log(`Downloading progress: ${Math.round(current / total * 100)}%`);
    });
    
    stream.finish(() => {
        console.log('Downloading finished');
    });
});
```

### Downloader.fileFromUri(uri)

```typescript
import { Downloader } from '@empathize/framework';

// index.html
console.log(Downloader.fileFromUri('https://www.youtube.com'));

// test.zip
console.log(Downloader.fileFromUri('https://example.com/test.zip'));
```

### Downloader.closeStreams(forced)

```typescript
import { Downloader } from '@empathize/framework';

Downloader.closeStreams().then(() => {
    console.log('All downloading streams was closed');
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://krypt0nn.gitbook.io/empathize/api/network-api/downloader.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
