> For the complete documentation index, see [llms.txt](https://guilhermesantos.gitbook.io/niro-health/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guilhermesantos.gitbook.io/niro-health/modules/archive.md).

# Archive

### Imports

{% tabs %}
{% tab title="Service" %}

```typescript
import { ArchiveService } from 'niro-health';
```

{% endtab %}

{% tab title="Module" %}

```typescript
import { ArchiveModule } from 'niro-health';
```

{% endtab %}

{% tab title="Interface" %}

```typescript
import type { IArchiveService } from 'niro-health';
```

{% endtab %}
{% endtabs %}

### Method of Use

To use this module, you need to inject it into the desired service.

> In the example below, I created a **`test.txt`** file with the following content **`"Hello World"`**. Remember that the write stream must contain the **`.zip`** or **`.gz`** extension, as it is a file in **`zip`** format.

#### Test results

{% file src="/files/7Q3emvsXlFMeOvwcEC9x" %}

{% file src="/files/92zuAa1YRaKWBiExxPew" %}

```typescript
import { Module } from '@nestjs/common';
import { ArchiveService } from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IArchiveService',
      useClass: ArchiveService,
    },
  ],
})
export class AppModule {}
```

Importing the service inside the module.

{% code title="app.service.ts" overflow="wrap" %}

```typescript
import { Inject, Injectable } from '@nestjs/common';
import type { IArchiveService } from 'niro-health';

import * as fs from 'fs';
import * as path from 'path';

@Injectable()
export class AppService {
  constructor(
    @Inject('IArchiveService')
    private readonly archiveService: IArchiveService,
  ) {}

  async createFileZIP() {
    const writeStream = fs.createWriteStream(
      path.resolve(__dirname, '../src', 'niro_logo.zip'),
    );
    const readStream = fs.createReadStream(
      path.resolve(__dirname, '../src', 'Niro Health - Logo.png'),
    );
    return await this.archiveService.joinWithReaders(writeStream, [
      {
        filename: 'niro_health.png',
        stream: readStream,
        version: '1',
      },
    ]);
  }
}
```

{% endcode %}

### Without dependencies

You won't need to connect the pieces with any other module.

### Properties

<table><thead><tr><th width="266.3333333333333">Property</th><th width="115" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>COMPRESSIONLEVEL</code></td><td align="center"><code>static</code></td><td><code>The compression level used to create the zip file.</code></td></tr></tbody></table>

### Methods

<table><thead><tr><th width="266.3333333333333">Method</th><th width="117" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>_zlibCompressionLevel</code></td><td align="center"><code>private</code></td><td><code>Returns the zlib compression level based on the compression level.</code></td></tr><tr><td><code>_base</code></td><td align="center"><code>private</code></td><td><code>Returns the instance of the archiver.</code></td></tr><tr><td><code>setCompressionLevel</code></td><td align="center"><code>public</code></td><td><code>Set the compression level used to create the zip file.</code></td></tr><tr><td><code>getCompressionLevel</code></td><td align="center"><code>public</code></td><td><code>Get the compression level used to create the zip file.</code></td></tr><tr><td><code>joinWithReaders</code></td><td align="center"><code>public</code></td><td><code>Join the files with the zip file.</code></td></tr></tbody></table>
