npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-s3-archiver

v1.0.3

Published

Archives files from an AWS S3 bucket with stream and stores the zip file in S3.

Downloads

434

Readme

AWS S3 Archiver

TypeScript Node.js TEST codecov npm version NPM License

Introduction

Based on AWS SDK v3 and archiver, use stream to archive files in the AWS S3 storage bucket and generate a zip file to store it back in S3.

Developed and full support for TypeScript. Supports ES Modules and CommonJS.

Installation

npm i aws-s3-archiver

Description

/**
 * Archives files from an AWS S3 bucket with stream and stores the zip file in S3.
 *
 * @param {string} sourceBucket - The name of the source S3 bucket.
 * @param {string} sourcePath - The path in the source bucket where the files to be archived are located.
 * @param {string} targetFileName - The name of the zip file. Defaults to 'archive'.
 * @param {string[]} sourceFileList - An array of file names to be archived. If empty, all files in the source will be archived.
 * @param {string} targetBucket - The name of the target S3 bucket where the zip file will be stored. Defaults to the source bucket.
 * @param {string} targetPath - The path in the target bucket where the zip file will be stored. Defaults to the source path.
 * @param {object} s3ClientOptions - Options for the S3 client. Defaults to an empty object.
 * @param {object} zipOptions - Options for the archiver. Defaults to an empty object.
 * @param {boolean} debugFlag - Flag to enable debug logging. Defaults to false.
 * @returns {Promise<object>} A promise that resolves with s3Upload Response when the zip file has been created and stored in S3.
 */

Usage

  1. Minimal - With the minimum number of parameters, it will archive all files in the provided bucket/path and generate a file named 'archive.zip' in the same directory.

    import { s3Zip } from 'aws-s3-archiver';
    
    const result = await s3Zip('sourceBucket', 'sourcePath');
    console.log(result);
  2. Archive all files in the provided bucket/path and generate a zip file with the given name in the same directory.

    import { s3Zip } from 'aws-s3-archiver';
    
    const result = await s3Zip('sourceBucket', 'sourcePath', 'targetFileName');
    console.log(result);
  3. Archive specified list of files in the the provided bucket/path.

    import { s3Zip } from 'aws-s3-archiver';
    
    const result = await s3Zip('sourceBucket', 'sourcePath', 'targetFileName', [
        'file1.txt',
        'file2.pdf',
    ]);
    console.log(result);
  4. Archive all files in the provided bucket/path and generate zip file with the given bucket/path.

    import { s3Zip } from 'aws-s3-archiver';
    
    const result = await s3Zip(
        'sourceBucket',
        'sourcePath',
        'targetFileName',
        [],
        'targetBucket',
        'targetPath',
    );
    console.log(result);
  5. Customize S3Client and compression attributes.

    S3Client Options: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/ - index for S3Client Configuration

    ZIP Options: https://www.archiverjs.com/docs/archiver#zip-options

    import { s3Zip } from 'aws-s3-archiver';
    
    const result = await s3Zip(
        'sourceBucket',
        'sourcePath',
        'archive',
        [],
        'targetBucket',
        'targetPath',
        { region: 'us-east-1' },
        { zlib: { level: 9 } },
    );
    console.log(result);
  6. If you need print out debug logs for aws sdk list/get command, set the debugFlag to true.

    import { s3Zip } from 'aws-s3-archiver';
    
    const result = await s3Zip(
        'sourceBucket',
        'sourcePath',
        'archive',
        [],
        'targetBucket',
        'targetPath',
        { region: 'us-east-1' },
        { zlib: { level: 9 } },
        true,
    );
    console.log(result);

Test

npm run test

Releases / Changelogs

1.0.0 - Initial stable release

1.0.1 - Update README.md with Usage examples

1.0.2 - Add debugFlag to enable/disable aws sdk list/get command logging.

1.0.3 - Fixed a bug that allows an empty path.