# s3-etag

> Generate an accurate S3 ETAG for multipart uploads in Node.js

Latest version **1.0.5** (published 2024-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install s3-etag
pnpm add s3-etag
yarn add s3-etag
bun add s3-etag
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2024-05-22 |
| First published | 2021-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Richard Willis |
| Maintainers | badsyntax |
| Keywords | s3, etag, hash, md5, aws |

## Links

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

## 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.5 (latest) — 2024-05-22
- 1.0.4 — 2023-10-01
- 1.0.3 — 2022-02-08
- 1.0.2 — 2022-02-08
- 1.0.1 — 2022-02-08
- 1.0.0 — 2022-01-12
- 0.0.7 — 2021-12-17
- 0.0.6 — 2021-12-16
- 0.0.5 — 2021-12-16
- 0.0.4 — 2021-12-16
- 0.0.3 — 2021-12-16

## README

# S3 ETAG

[![Build, Test & Publish](https://github.com/badsyntax/s3-etag/actions/workflows/build-test-publish.yml/badge.svg)](https://github.com/badsyntax/s3-etag/actions/workflows/build-test-publish.yml)
[![CodeQL](https://github.com/badsyntax/s3-etag/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/badsyntax/s3-etag/actions/workflows/codeql-analysis.yml)

Generate an accurate S3 ETAG in Node.js for any file (including multipart). 

Please Note, this only works for unencrypted buckets.

## Installation

```console
npm install s3-etag
```

## Usage

```ts
import { generateETag } from 's3-etag';

// Simple MD5 hash of contents for non-multipart files
const etag = generateETag(absoluteFilePath);

// MD5 hash of combined contents & part number (see below) for multipart files
const partSizeInBytes = 10 * 1024 * 1024; // 10mb
const etag = generateETag(absoluteFilePath, partSizeInBytes);
```

## How It Works

This is a Node.js implementation of [this algorithm](https://stackoverflow.com/a/19896823/492325).

At a high level:

- If no `partSizeInBytes` is specified, return MD5 hash of file contents
- If `partSizeInBytes` is specified:
  - Generate parts by comparing `partSizeInBytes` to the file size
  - Read each part from the file, MD5 hash the part, and append it to a global combined hash
  - Once all parts are processed, generate a new MD5 from the global combined hash, and suffix with the amount of parts

## License

See [LICENSE.md](./LICENSE.md).

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