# lambdafs

> Efficient (de)compression package for AWS Lambda

Latest version **2.1.1** (published 2021-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install lambdafs
pnpm add lambdafs
yarn add lambdafs
bun add lambdafs
```

Provides the command `lambdafs`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2021-12-24 |
| First published | 2019-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 10.16 |
| Dependencies | 1 |
| Unpacked size | 554.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Alix Axel |
| Maintainers | alixaxel |
| Keywords | aws, brotli, compression, decompression, gzip, lambda, serverless, tarball |

## Links

- npm: https://www.npmjs.com/package/lambdafs
- Repository: https://github.com/alixaxel/lambdafs
- Issues: https://github.com/alixaxel/lambdafs/issues
- npm.io page: https://npm.io/package/lambdafs

## Dependencies (1)

- [tar-fs](https://npm.io/package/tar-fs.md) *

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.1.1 (latest) — 2021-12-24
- 2.1.0 — 2021-12-24
- 2.0.3 — 2021-03-13
- 2.0.2 — 2021-02-05
- 2.0.1 — 2020-12-08
- 2.0.0 — 2020-08-12
- 1.3.0 — 2019-10-12
- 1.2.0 — 2019-09-15
- 1.1.0 — 2019-09-14
- 1.0.1 — 2019-09-14
- 1.0.0 — 2019-09-14

## README

# LambdaFS

[![lambdafs](https://img.shields.io/npm/v/lambdafs.svg?style=for-the-badge)](https://www.npmjs.com/package/lambdafs)
[![TypeScript](https://img.shields.io/npm/types/chrome-aws-lambda?style=for-the-badge)](https://www.typescriptlang.org/dt/search?search=lambdafs)
[![Donate](https://img.shields.io/badge/donate-paypal-orange.svg?style=for-the-badge)](https://paypal.me/alixaxel)

Efficient (de)compression package for AWS Lambda, supporting **Brolti**, **Gzip** and **Tarballs**

## Install

```shell
npm install lambdafs --save-prod
```

## CLI

This package provides a [`brotli` CLI command](/bin) to conveniently compress files and/or folders.

```shell
npx lambdafs /path/to/compress
```

The resulting file will be a (potentially tarballed) Brotli compressed file, with the same base name as the source.

> Due to the highest compression level, it might take a while to compress large files (100MB ~ 5 minutes).

## Usage

The `nodejs12.x` or `nodejs14.x` AWS Lambda runtime is required for this package to work properly.

```javascript
const lambdafs = require('lambdafs');

exports.handler = async (event, context) => {
  try {
    let file = __filename; // /var/task/index.js
    let folder = __dirname; // /var/task

    // Compressing
    let compressed = {
      file: await lambdafs.deflate(file), // /tmp/index.js.gz
      folder: await lambdafs.deflate(folder), // /tmp/task.tar.gz
    };

    // Decompressing
    let decompressed = {
      file: await lambdafs.inflate(compressed.file), // /tmp/index.js
      folder: await lambdafs.inflate(compressed.folder), // /tmp/task
    };

    return context.succeed({ file, folder, compressed, decompressed });
  } catch (error) {
    return context.fail(error);
  }
};
```

## API

### `deflate(path: string): Promise<string>`

Compresses a file/folder with Gzip and returns the path to the compressed (tarballed) file.

> The resulting file will be saved under the default temporary directory (`/tmp` on AWS Lambda).

Due to costly execution time on AWS Lambda, Gzip is *always* used to compress files.

### `inflate(path: string): Promise<string>`

Decompresses a (tarballed) Brotli or Gzip compressed file and returns the path to the decompressed file/folder.

> The resulting file(s) will be saved under the default temporary directory (`/tmp` on AWS Lambda).

Supported extensions are: `.br`, `.gz`, `.tar`, `.tar.br` (and `.tbr`), `.tar.gz` (and `.tgz`).

> For tarballs, original file modes are perserved. For any other files `0700` is assumed.

## Rationale

Getting large resources onto AWS Lambda can be a challenging task due to the [deployment package size limit](https://docs.aws.amazon.com/lambda/latest/dg/limits.html#w291aac11c35c15):

| Limit  | Context                     |
| ------ | --------------------------- |
| 50 MB  | Zipped, for direct uploads. |
| 250 MB | Unzipped, S3 and layers.    |

For this reason, it's important to achieve a very high compression ratio as well as fast decompression times.

This is where the [Brotli algorithm](https://www.opencpu.org/posts/brotli-benchmarks/) comes in:

![Brotli Benchmarks](https://i.imgur.com/98UvYQL.png)

It allows us to get the best compression ratio and fast decompression times (at the expense of a slow compression).

## License

MIT

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