Skip to content

Commit

Permalink
Merge pull request #7 from badsyntax/readme
Browse files Browse the repository at this point in the history
Update README with better usage instructions
  • Loading branch information
badsyntax authored Dec 17, 2021
2 parents 9345549 + c14fa5a commit b57700e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@ npm install s3-etag
```ts
import { generateETag } from 's3-etag';

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

expect(etag).toBe('ba0b9fe20dc67b0e4c478ab3c03dc5ce');
// 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).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "s3-etag",
"version": "0.0.0",
"private": false,
"description": "Generate an S3 ETAG for multipart uploads in Node.js",
"description": "Generate an accurate S3 ETAG for multipart uploads in Node.js",
"exports": "./index.js",
"type": "module",
"scripts": {
Expand Down

0 comments on commit b57700e

Please sign in to comment.