📝Archive
The module responsible for create a zip file with the files.
Imports
import { ArchiveService } from 'niro-health';
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 inzip
format.
Test results
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.
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',
},
]);
}
}
Without dependencies
You won't need to connect the pieces with any other module.
Properties
COMPRESSIONLEVEL
static
The compression level used to create the zip file.
Methods
_zlibCompressionLevel
private
Returns the zlib compression level based on the compression level.
_base
private
Returns the instance of the archiver.
setCompressionLevel
public
Set the compression level used to create the zip file.
getCompressionLevel
public
Get the compression level used to create the zip file.
joinWithReaders
public
Join the files with the zip file.
Last updated