stream-to-etag 1.1.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +12 -0
- package/esm/index.js +17 -0
- package/index.d.ts +2 -0
- package/index.js +20 -0
- package/package.json +25 -56
- package/main/index.js +0 -17
- package/module/index.js +0 -14
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 Dan Lynch <pyramation@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Stream to ETag
|
|
2
2
|
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img height="250" src="https://github.com/user-attachments/assets/d0456af5-b6e9-422e-a45d-2574d5be490f" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center" width="100%">
|
|
8
|
+
<a href="https://github.com/launchql/launchql-2.0/actions/workflows/run-tests.yaml">
|
|
9
|
+
<img height="20" src="https://github.com/launchql/launchql-2.0/actions/workflows/run-tests.yaml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/launchql/launchql-2.0/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/stream-to-etag"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql-2.0?filename=packages%2Fstream-to-etag%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
3
15
|
Calculates Etag/S3 MD5 sum given a readable stream. Uses the same algorithm that S3 uses to calculate the `ETag`.
|
|
4
16
|
|
|
5
17
|
This is especially useful for verifying large files uploaded using multipart S3 API, enabling use of `createReadStream` to keep memory usage low.
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createHash } from 'etag-hash';
|
|
2
|
+
export default function stream2etag(stream, partSizeInMb = 5) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
const hash = createHash(partSizeInMb);
|
|
5
|
+
stream
|
|
6
|
+
.on('error', (error) => {
|
|
7
|
+
reject(error);
|
|
8
|
+
})
|
|
9
|
+
.on('data', (chunk) => {
|
|
10
|
+
const buf = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk;
|
|
11
|
+
hash.update(buf);
|
|
12
|
+
})
|
|
13
|
+
.on('end', () => {
|
|
14
|
+
resolve(hash.digest());
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = stream2etag;
|
|
4
|
+
const etag_hash_1 = require("etag-hash");
|
|
5
|
+
function stream2etag(stream, partSizeInMb = 5) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const hash = (0, etag_hash_1.createHash)(partSizeInMb);
|
|
8
|
+
stream
|
|
9
|
+
.on('error', (error) => {
|
|
10
|
+
reject(error);
|
|
11
|
+
})
|
|
12
|
+
.on('data', (chunk) => {
|
|
13
|
+
const buf = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk;
|
|
14
|
+
hash.update(buf);
|
|
15
|
+
})
|
|
16
|
+
.on('end', () => {
|
|
17
|
+
resolve(hash.digest());
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,71 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-to-etag",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Calculates Etag/S3 MD5 sum given a readable stream. Uses the same algorithm that S3 uses to calculate the ETag.",
|
|
3
|
+
"version": "2.0.3",
|
|
5
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
|
-
"
|
|
5
|
+
"description": "Calculates Etag/S3 MD5 sum given a readable stream. Uses the same algorithm that S3 uses to calculate the ETag.",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/launchql/launchql",
|
|
7
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
|
-
"main": "main/index.js",
|
|
9
|
-
"module": "module/index.js",
|
|
10
|
-
"directories": {
|
|
11
|
-
"lib": "src",
|
|
12
|
-
"test": "__tests__"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"main",
|
|
16
|
-
"module"
|
|
17
|
-
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build:main": "cross-env BABEL_ENV=production babel src --out-dir main --delete-dir-on-start",
|
|
20
|
-
"build:module": "cross-env MODULE=true babel src --out-dir module --delete-dir-on-start",
|
|
21
|
-
"build": "npm run build:module && npm run build:main",
|
|
22
|
-
"prepublish": "npm run build",
|
|
23
|
-
"dev": "cross-env NODE_ENV=development babel-node src/index",
|
|
24
|
-
"watch": "cross-env NODE_ENV=development babel-watch src/index",
|
|
25
|
-
"lint": "eslint src --fix",
|
|
26
|
-
"test": "jest",
|
|
27
|
-
"test:watch": "jest --watch",
|
|
28
|
-
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
29
|
-
},
|
|
30
11
|
"publishConfig": {
|
|
31
|
-
"access": "public"
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
32
14
|
},
|
|
33
15
|
"repository": {
|
|
34
16
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/launchql/launchql"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/launchql/launchql/issues"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
24
|
+
"clean": "rimraf dist/**",
|
|
25
|
+
"prepare": "npm run build",
|
|
26
|
+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
|
|
27
|
+
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
28
|
+
"lint": "eslint . --fix",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch"
|
|
36
31
|
},
|
|
37
32
|
"keywords": [
|
|
38
33
|
"s3",
|
|
39
34
|
"etag"
|
|
40
35
|
],
|
|
41
|
-
"bugs": {
|
|
42
|
-
"url": "https://github.com/pyramation/stream-to-etag/issues"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@babel/cli": "7.11.6",
|
|
46
|
-
"@babel/core": "7.11.6",
|
|
47
|
-
"@babel/node": "^7.10.5",
|
|
48
|
-
"@babel/plugin-proposal-class-properties": "7.10.4",
|
|
49
|
-
"@babel/plugin-proposal-export-default-from": "7.10.4",
|
|
50
|
-
"@babel/plugin-proposal-object-rest-spread": "7.11.0",
|
|
51
|
-
"@babel/plugin-transform-runtime": "7.11.5",
|
|
52
|
-
"@babel/preset-env": "7.11.5",
|
|
53
|
-
"babel-core": "7.0.0-bridge.0",
|
|
54
|
-
"babel-eslint": "10.1.0",
|
|
55
|
-
"babel-jest": "25.1.0",
|
|
56
|
-
"babel-watch": "^7.0.0",
|
|
57
|
-
"cross-env": "^7.0.2",
|
|
58
|
-
"eslint": "6.8.0",
|
|
59
|
-
"eslint-config-prettier": "^6.10.0",
|
|
60
|
-
"eslint-plugin-prettier": "^3.1.2",
|
|
61
|
-
"glob": "^7.1.3",
|
|
62
|
-
"jest": "^24.5.0",
|
|
63
|
-
"jest-in-case": "^1.0.2",
|
|
64
|
-
"prettier": "^2.1.2",
|
|
65
|
-
"regenerator-runtime": "^0.13.7"
|
|
66
|
-
},
|
|
67
36
|
"dependencies": {
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
37
|
+
"etag-hash": "^2.0.3"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "546607b8de61b57f332562bfd8418cd5fac63a6a"
|
|
71
40
|
}
|
package/main/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _etagHash = require("etag-hash");
|
|
4
|
-
|
|
5
|
-
module.exports = function stream2etag(stream) {
|
|
6
|
-
var partSizeInMb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
|
|
7
|
-
return new Promise(function (resolve, reject) {
|
|
8
|
-
var hash = (0, _etagHash.createHash)(partSizeInMb);
|
|
9
|
-
stream.on('error', function (error) {
|
|
10
|
-
reject(error);
|
|
11
|
-
}).on('data', function (chunk) {
|
|
12
|
-
hash.update(chunk);
|
|
13
|
-
}).on('end', function () {
|
|
14
|
-
resolve(hash.digest());
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
};
|
package/module/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'etag-hash';
|
|
2
|
-
|
|
3
|
-
module.exports = function stream2etag(stream, partSizeInMb = 5) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const hash = createHash(partSizeInMb);
|
|
6
|
-
stream.on('error', function (error) {
|
|
7
|
-
reject(error);
|
|
8
|
-
}).on('data', function (chunk) {
|
|
9
|
-
hash.update(chunk);
|
|
10
|
-
}).on('end', function () {
|
|
11
|
-
resolve(hash.digest());
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
};
|