etag-stream 1.1.6 → 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 +13 -0
- package/esm/index.js +30 -0
- package/index.d.ts +13 -0
- package/index.js +32 -0
- package/package.json +25 -55
- package/main/index.js +0 -69
- package/module/index.js +0 -38
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,18 @@
|
|
|
1
1
|
# ETag Stream
|
|
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/etag-stream"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql-2.0?filename=packages%2Fetag-stream%2Fpackage.json"/></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
A Transform stream that calculates Etag/S3 MD5 sum. Uses the same algorithm that S3 uses to calculate the `ETag`.
|
|
4
17
|
|
|
5
18
|
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,30 @@
|
|
|
1
|
+
import { Transform } from 'stream';
|
|
2
|
+
import { createHash } from 'etag-hash';
|
|
3
|
+
class ETagStream extends Transform {
|
|
4
|
+
mode;
|
|
5
|
+
hash;
|
|
6
|
+
constructor(opts = {}) {
|
|
7
|
+
const { partSizeInMb = 5, mode = 'through' } = opts;
|
|
8
|
+
super();
|
|
9
|
+
this.mode = mode;
|
|
10
|
+
this.hash = createHash(partSizeInMb);
|
|
11
|
+
}
|
|
12
|
+
_transform(chunk, _encoding, callback) {
|
|
13
|
+
this.hash.update(chunk);
|
|
14
|
+
if (this.mode === 'through') {
|
|
15
|
+
this.push(chunk);
|
|
16
|
+
}
|
|
17
|
+
callback();
|
|
18
|
+
}
|
|
19
|
+
_flush(callback) {
|
|
20
|
+
const digest = this.hash.digest();
|
|
21
|
+
if (this.mode === 'through') {
|
|
22
|
+
this.emit('etag', digest);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.push(digest);
|
|
26
|
+
}
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export default ETagStream;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Transform, TransformCallback } from 'stream';
|
|
2
|
+
interface ETagStreamOptions {
|
|
3
|
+
partSizeInMb?: number;
|
|
4
|
+
mode?: 'through' | 'buffer';
|
|
5
|
+
}
|
|
6
|
+
declare class ETagStream extends Transform {
|
|
7
|
+
private mode;
|
|
8
|
+
private hash;
|
|
9
|
+
constructor(opts?: ETagStreamOptions);
|
|
10
|
+
_transform(chunk: any, _encoding: BufferEncoding, callback: TransformCallback): void;
|
|
11
|
+
_flush(callback: TransformCallback): void;
|
|
12
|
+
}
|
|
13
|
+
export default ETagStream;
|
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const stream_1 = require("stream");
|
|
4
|
+
const etag_hash_1 = require("etag-hash");
|
|
5
|
+
class ETagStream extends stream_1.Transform {
|
|
6
|
+
mode;
|
|
7
|
+
hash;
|
|
8
|
+
constructor(opts = {}) {
|
|
9
|
+
const { partSizeInMb = 5, mode = 'through' } = opts;
|
|
10
|
+
super();
|
|
11
|
+
this.mode = mode;
|
|
12
|
+
this.hash = (0, etag_hash_1.createHash)(partSizeInMb);
|
|
13
|
+
}
|
|
14
|
+
_transform(chunk, _encoding, callback) {
|
|
15
|
+
this.hash.update(chunk);
|
|
16
|
+
if (this.mode === 'through') {
|
|
17
|
+
this.push(chunk);
|
|
18
|
+
}
|
|
19
|
+
callback();
|
|
20
|
+
}
|
|
21
|
+
_flush(callback) {
|
|
22
|
+
const digest = this.hash.digest();
|
|
23
|
+
if (this.mode === 'through') {
|
|
24
|
+
this.emit('etag', digest);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.push(digest);
|
|
28
|
+
}
|
|
29
|
+
callback();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.default = ETagStream;
|
package/package.json
CHANGED
|
@@ -1,70 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "etag-stream",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A Transform stream that calculates Etag/S3 MD5 sum. 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": "A Transform stream that calculates Etag/S3 MD5 sum. 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/etag-stream/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
|
-
"jest": "^24.5.0",
|
|
62
|
-
"jest-in-case": "^1.0.2",
|
|
63
|
-
"prettier": "^2.1.2",
|
|
64
|
-
"regenerator-runtime": "^0.13.7"
|
|
65
|
-
},
|
|
66
36
|
"dependencies": {
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
"etag-hash": "^2.0.3"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "546607b8de61b57f332562bfd8418cd5fac63a6a"
|
|
70
40
|
}
|
package/main/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
6
|
-
|
|
7
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
-
|
|
9
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
10
|
-
|
|
11
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
12
|
-
|
|
13
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
-
|
|
15
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
16
|
-
|
|
17
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
18
|
-
|
|
19
|
-
var stream = require('stream');
|
|
20
|
-
|
|
21
|
-
var etag = require('etag-hash');
|
|
22
|
-
|
|
23
|
-
var ETagStream = /*#__PURE__*/function (_stream$Transform) {
|
|
24
|
-
(0, _inherits2["default"])(ETagStream, _stream$Transform);
|
|
25
|
-
|
|
26
|
-
var _super = _createSuper(ETagStream);
|
|
27
|
-
|
|
28
|
-
function ETagStream() {
|
|
29
|
-
var _this;
|
|
30
|
-
|
|
31
|
-
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
|
-
(0, _classCallCheck2["default"])(this, ETagStream);
|
|
33
|
-
var _opts$partSizeInMb = opts.partSizeInMb,
|
|
34
|
-
partSizeInMb = _opts$partSizeInMb === void 0 ? 5 : _opts$partSizeInMb,
|
|
35
|
-
_opts$mode = opts.mode,
|
|
36
|
-
mode = _opts$mode === void 0 ? 'through' : _opts$mode;
|
|
37
|
-
_this = _super.call(this);
|
|
38
|
-
_this.mode = mode;
|
|
39
|
-
_this.hash = etag.createHash(partSizeInMb);
|
|
40
|
-
return _this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
(0, _createClass2["default"])(ETagStream, [{
|
|
44
|
-
key: "_write",
|
|
45
|
-
value: function _write(chunk, enc, next) {
|
|
46
|
-
this.hash.update(chunk);
|
|
47
|
-
|
|
48
|
-
if (this.mode === 'through') {
|
|
49
|
-
this.push(chunk);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
next();
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
key: "_flush",
|
|
56
|
-
value: function _flush(done) {
|
|
57
|
-
if (this.mode === 'through') {
|
|
58
|
-
this.emit('etag', this.hash.digest());
|
|
59
|
-
} else {
|
|
60
|
-
this.push(this.hash.digest());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
done();
|
|
64
|
-
}
|
|
65
|
-
}]);
|
|
66
|
-
return ETagStream;
|
|
67
|
-
}(stream.Transform);
|
|
68
|
-
|
|
69
|
-
module.exports = ETagStream;
|
package/module/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const stream = require('stream');
|
|
2
|
-
|
|
3
|
-
const etag = require('etag-hash');
|
|
4
|
-
|
|
5
|
-
class ETagStream extends stream.Transform {
|
|
6
|
-
constructor(opts = {}) {
|
|
7
|
-
const {
|
|
8
|
-
partSizeInMb = 5,
|
|
9
|
-
mode = 'through'
|
|
10
|
-
} = opts;
|
|
11
|
-
super();
|
|
12
|
-
this.mode = mode;
|
|
13
|
-
this.hash = etag.createHash(partSizeInMb);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
_write(chunk, enc, next) {
|
|
17
|
-
this.hash.update(chunk);
|
|
18
|
-
|
|
19
|
-
if (this.mode === 'through') {
|
|
20
|
-
this.push(chunk);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
next();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_flush(done) {
|
|
27
|
-
if (this.mode === 'through') {
|
|
28
|
-
this.emit('etag', this.hash.digest());
|
|
29
|
-
} else {
|
|
30
|
-
this.push(this.hash.digest());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
done();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = ETagStream;
|