S3 ETAG
Generate an accurate S3 ETAG for any file (including multipart).
Installation
npm install s3-etag
(TypeScript type definitions are included in the package.)
Usage
import { generateETag } from 's3-etag';
const etag = generateETag(absoluteFilePath);
const partSizeInBytes = 10 * 1024 * 1024;
const etag = generateETag(absoluteFilePath, partSizeInBytes);
How It Works
This is a Node.js implementation of this algorithm.
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.