# aws-s3-archiver

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

Latest version **1.0.3** (published 2024-04-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install aws-s3-archiver
pnpm add aws-s3-archiver
yarn add aws-s3-archiver
bun add aws-s3-archiver
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-04-11 |
| First published | 2023-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Wolfsin |
| Maintainers | wolfsin |
| Keywords | aws, s3, lambda, archiver, typescript |

## Links

- npm: https://www.npmjs.com/package/aws-s3-archiver
- Repository: https://github.com/Wolfsin/aws-s3-archiver
- Homepage: https://github.com/Wolfsin/aws-s3-archiver#readme
- Issues: https://github.com/Wolfsin/aws-s3-archiver/issues
- npm.io page: https://npm.io/package/aws-s3-archiver

## Dependencies (3)

- [archiver](https://npm.io/package/archiver.md) ^6.0.1
- [@aws-sdk/client-s3](https://npm.io/package/@aws-sdk/client-s3.md) ^3.456.0
- [@aws-sdk/lib-storage](https://npm.io/package/@aws-sdk/lib-storage.md) ^3.456.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2024-04-11
- 1.0.2 — 2023-12-08
- 1.0.1 — 2023-12-02
- 1.0.0 — 2023-12-02

## README

# AWS S3 Archiver

[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) [![Node.js TEST](https://github.com/Wolfsin/aws-s3-archiver/actions/workflows/npm-test.yml/badge.svg?branch=main)](https://github.com/Wolfsin/aws-s3-archiver/actions/workflows/npm-test.yml) [![codecov](https://codecov.io/gh/Wolfsin/aws-s3-archiver/graph/badge.svg?token=2BA5F5JJRS)](https://codecov.io/gh/Wolfsin/aws-s3-archiver) [![npm version](https://badge.fury.io/js/aws-s3-archiver.svg)](https://badge.fury.io/js/aws-s3-archiver) ![NPM License](https://img.shields.io/npm/l/aws-s3-archiver)

## Introduction

Based on [AWS SDK v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/) and [archiver](https://github.com/archiverjs/node-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

```typescript
/**
 * 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.

    ```typescript
    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.

    ```typescript
    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.

    ```typescript
    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.

    ```typescript
    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

    ```typescript
    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.

    ```typescript
    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.

---
_Source: https://npm.io/package/aws-s3-archiver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
