Skip to content

Commit

Permalink
adding adm zip solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dheepak-aot committed Dec 18, 2024
1 parent fb71f43 commit aafc68c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LoggerService, InjectLogger } from "@sims/utilities/logger";
import { SshService } from "./ssh.service";
import { unzip } from "node:zlib";
import * as Client from "ssh2-sftp-client";
import * as path from "path";
import { SFTPConfig } from "@sims/utilities/config";
Expand All @@ -14,6 +13,7 @@ import {
LINE_BREAK_SPLIT_REGEX,
SFTP_ARCHIVE_DIRECTORY,
} from "@sims/integrations/constants";
import * as AdmZip from "adm-zip";

/**
* Provides the basic features to enable the SFTP integration.
Expand Down Expand Up @@ -177,12 +177,9 @@ export abstract class SFTPIntegrationBase<DownloadType> {
// Read all the file content and create a buffer with 'ascii' encoding.
let fileContent = await client.get(remoteFilePath);
if (options?.checkIfZipFile) {
unzip(fileContent as Buffer, (err, buffer) => {
if (err) {
throw new Error("Error while unzipping file.");
}
fileContent = buffer;
});
const zipFile = new AdmZip(fileContent as Buffer);
const [extractedFile] = zipFile.getEntries();
fileContent = extractedFile.getData();
}
// Convert the file content to an array of text lines and remove possible blank lines.
return fileContent
Expand Down
19 changes: 19 additions & 0 deletions sources/packages/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sources/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@nestjs/terminus": "^10.2.3",
"@nestjs/typeorm": "^10.0.2",
"@types/ssh2-sftp-client": "^9.0.3",
"adm-zip": "^0.5.16",
"axios": "^1.7.4",
"bull": "^4.12.2",
"clamscan": "^2.2.1",
Expand Down Expand Up @@ -99,6 +100,7 @@
"@suites/di.nestjs": "^3.0.0",
"@suites/doubles.jest": "^3.0.0",
"@suites/unit": "^3.0.0",
"@types/adm-zip": "^0.5.7",
"@types/clamscan": "^2.0.8",
"@types/express": "^4.17.8",
"@types/faker": "^5.1.5",
Expand Down Expand Up @@ -177,4 +179,4 @@
"^@sims/auth(|/.*)$": "<rootDir>/libs/auth/src/$1"
}
}
}
}

0 comments on commit aafc68c

Please sign in to comment.