# Archive

## Stream object

Code examples below

### stream.start(callback)

Specify event that will be called when unpacking will be started

### stream.progress(callback)

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

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

### stream.finish(callback)

Specify event that will be called when unpacking will be finished

### stream.error(callback)

Specify event that will be called when unpacking can't be started

### stream.close(forced)

Close unpacking stream

## Archive class

### Archive.getType(path)

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

console.log(Archive.getType('my_archive.zip')); // zip
```

### Archive.getInfo(path)

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

Archive.getInfo('my_archive.zip').then((info) => {
    console.log(`Archive type: ${info.type}`); // zip
    console.log(`Unpacked size: ${info.size.unpacked} bytes`);
    console.log(`Compressed size: ${info.size.compressed} bytes`);
    
    console.log("\r\nFiles:");
    
    for (const file of info.files)
    {
        console.log(`Path: ${file.path}`);
        console.log(`Unpacked size: ${file.size.unpacked} bytes`);
        console.log(`Compressed size: ${file.size.compressed} bytes`);
        
        console.log("\r\n");
    }
});
```

### Archive.extract(path, unpackDir)

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

Archive.extract('my_archive.zip', 'path/to/unpack/folder').then((stream) => {
    stream.progressInterval = 1000;
    
    stream.start(() => {
        console.log('Extracting started');
    });
    
    stream.progress((current, total, difference) => {
        console.log(`Extracting progress: ${Math.round(current / total * 100)}%`);
    });
    
    stream.finish(() => {
        console.log('Extracting finished');
    });
});
```

### Archive.closeStreams(forced)

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

Archive.closeStreams().then(() => {
    console.log('All archive extracting streams was closed');
});
```


---

# Agent Instructions: 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:

```
GET https://krypt0nn.gitbook.io/empathize/api/os-api/archive.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
