Down a .rmp file from S3 using Javascript V2 sdk and aws lambda

I am trying download a .rpm file from S3 and exract .rmp file using rpm-extract npm library. I am using sdk v2 and aws lambda. I am getting error while extracting the rmp files which is thrwon from here https://github.com/dowjones/rpm-extract/blob/master/src/gzUnzip.js#L15. I am not sure how the .rpm file in S3 bucket is compressed. But I am assuming that when I download the .rpm files from S3 and write to lambda /tmp folder, rpm file is getting compressed again. Is there a way I can directly download the file from S3 without reading and writing the content? I can’t use sdk V3. I am using Nodejs aws lambda to run the code. or is there any other way to extract .rpm files in javascript. Here is code –

const AWS = require('aws-sdk');
const fs = require('fs');
const rpmExtract = require('rpm-extract')

// Create an S3 instance
const s3 = new AWS.S3();


const downloadFileFromS3 = async (bucket, key) => {
    const tempFilePath = '/tmp/content.rmp'; // Store in /tmp directory
    console.log('Temp file path set:', tempFilePath);

    const params = {
        Bucket: bucket,
        Key: key
    };
    console.log('Params set for S3 getObject:', params);

    console.log('Downloading file from S3...');
    try {
        const data = await s3.getObject(params).promise();

        console.log('Writing file to disk...');
        fs.writeFileSync(tempFilePath, data.Body);

        console.log('File downloaded successfully:', tempFilePath);

        return tempFilePath;
    } catch (error) {
        console.error('Error downloading file from S3:', error);
        throw error;
    }
};

async function getCertsFromRpm(s3Bucket, s3Key) {
    try {
        console.log("Inside getCertsFromRpm function");
        const rpmFile = await downloadFileFromS3(s3Bucket, s3Key);
        console.log("RPM file downloaded successfully:", rpmFile);

        const files = await rpmExtract.default(rpmFile);
        console.log("RPM file extracted successfully. Total files:", files.length);

        // Filter out symbolic links and select only .pem files
        const pemFiles = files
            .filter((file) => !file.linkname && file.path.endsWith('.pem'))
            .map((file) => file.data.toString());

        console.log("Filtered PEM files:", pemFiles);
        return pemFiles;
    } catch (err) {
        console.error('Error extracting certificates from RPM:', err);
        return [];
    }
}

module.exports = {
    getCertsFromRpm
}

I tries using file stream too

const AWS = require('aws-sdk');
const fs = require('fs');
const rpmExtract = require('rpm-extract')
 
// Create an S3 instance
const s3 = new AWS.S3();
 
 
const downloadFileFromS3 = (bucket, key) => {
    const tempFilePath = '/tmp/content.rpm'; // Store in /tmp directory
    console.log('Temp file path set:', tempFilePath);
 
    const params = {
        Bucket: bucket,
        Key: key
    };
    console.log('Params set for S3 getObject:', params);
 
    console.log('Downloading file from S3...');
 
    return new Promise((resolve, reject) => {
        const fileStream = fs.createWriteStream(tempFilePath);
        console.log('Writable file stream created.');
 
        const s3Stream = s3.getObject(params).createReadStream();
        console.log('S3 read stream created.');
 
        s3Stream.on('error', (err) => {
            console.error('Error retrieving file from S3:', err);
            reject(err);
        });
 
        fileStream.on('error', (err) => {
            console.error('Error writing file to disk:', err);
            reject(err);
        });
 
        fileStream.on('close', () => {
            console.log('File downloaded successfully:', tempFilePath);
            resolve(tempFilePath);
        });
        console.log('Close listener added for file stream.');
 
        s3Stream.on('data', (data) => {
            console.log('Downloading data from S3...');
            console.log('Data received:', data.toString()); // Log the data being written
        });
        console.log('Data listener added for S3 stream.');
 
        s3Stream.on('end', () => {
            console.log('S3 download stream ended.');
        });
        console.log('End listener added for S3 stream.');
 
        s3Stream.pipe(fileStream);
        console.log('Piped S3 stream to file stream.');
    });
};
 
async function getCertsFromRpm(s3Bucket, s3Key) {
    try {
        console.log("Inside getCertsFromRpm function");
        const rpmFile = await downloadFileFromS3(s3Bucket, s3Key);
        console.log("RPM file downloaded successfully:", rpmFile);
 
        const files = await rpmExtract(rpmFile);
        console.log("RPM file extracted successfully. Total files:", files.length);
 
        // Filter out symbolic links and select only .pem files
        const pemFiles = files
            .filter((file) => !file.linkname && file.path.endsWith('.pem'))
            .map((file) => file.data.toString());
 
        console.log("Filtered PEM files:", pemFiles);
        return pemFiles;
    } catch (err) {
        console.error('Error extracting certificates from RPM:', err);
        return [];
    }
}
 
module.exports = {
    getCertsFromRpm
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật