@8ms/helpers 1.5.10 → 1.6.0
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/aws/s3/writeGzip.d.ts +3 -3
- package/aws/s3/writeGzip.js +2 -2
- package/package.json +3 -1
- package/stream/sort.d.ts +13 -0
- package/stream/sort.js +50 -0
package/aws/s3/writeGzip.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type
|
|
1
|
+
type WriteGzip = {
|
|
2
2
|
bucket: string;
|
|
3
3
|
data: any;
|
|
4
4
|
key: string;
|
|
@@ -8,5 +8,5 @@ type WriteBrotli = {
|
|
|
8
8
|
/**
|
|
9
9
|
* Write a gzip file to S3.
|
|
10
10
|
*/
|
|
11
|
-
declare const
|
|
12
|
-
export default
|
|
11
|
+
declare const writeGzip: ({ bucket, data, key, isJson, ...options }: WriteGzip) => Promise<any>;
|
|
12
|
+
export default writeGzip;
|
package/aws/s3/writeGzip.js
CHANGED
|
@@ -8,7 +8,7 @@ const writeFile_1 = __importDefault(require("./writeFile"));
|
|
|
8
8
|
/**
|
|
9
9
|
* Write a gzip file to S3.
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
11
|
+
const writeGzip = async ({ bucket, data, key, isJson, ...options }) => {
|
|
12
12
|
let finalData = data;
|
|
13
13
|
if (false !== isJson) {
|
|
14
14
|
finalData = JSON.stringify(data);
|
|
@@ -25,4 +25,4 @@ const writeBrotli = async ({ bucket, data, key, isJson, ...options }) => {
|
|
|
25
25
|
});
|
|
26
26
|
return apiResponse;
|
|
27
27
|
};
|
|
28
|
-
exports.default =
|
|
28
|
+
exports.default = writeGzip;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8ms/helpers",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
@@ -39,6 +39,8 @@
|
|
|
39
39
|
"babel-jest": "29.7.0",
|
|
40
40
|
"jest": "29.7.0",
|
|
41
41
|
"node-fetch": "3.3.2",
|
|
42
|
+
"stream-chain": "2.2.5",
|
|
43
|
+
"stream-json": "1.8.0",
|
|
42
44
|
"timezone-mock": "1.3.6",
|
|
43
45
|
"ts-node": "10.9.1",
|
|
44
46
|
"tslib": "2.6.2",
|
package/stream/sort.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const Transform: any;
|
|
2
|
+
/**
|
|
3
|
+
* Batch sort stream without overloading the memory limit.
|
|
4
|
+
* https://www.npmjs.com/package/fast-stream-sort
|
|
5
|
+
*/
|
|
6
|
+
declare class SortStreamer extends Transform {
|
|
7
|
+
constructor(options: any, comp: any);
|
|
8
|
+
_transform(data: any, _: any, callback: any): void;
|
|
9
|
+
_flush(): void;
|
|
10
|
+
fullflush(): void;
|
|
11
|
+
}
|
|
12
|
+
declare const sort: (comp: any, options: any) => SortStreamer;
|
|
13
|
+
export default sort;
|
package/stream/sort.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Transform = require('stream').Transform;
|
|
4
|
+
const batch = 15000;
|
|
5
|
+
/**
|
|
6
|
+
* Batch sort stream without overloading the memory limit.
|
|
7
|
+
* https://www.npmjs.com/package/fast-stream-sort
|
|
8
|
+
*/
|
|
9
|
+
class SortStreamer extends Transform {
|
|
10
|
+
constructor(options, comp) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.a = new Array(batch);
|
|
13
|
+
this.i = 0;
|
|
14
|
+
this.k = 0;
|
|
15
|
+
this.currentSize = batch;
|
|
16
|
+
this.isDone = false;
|
|
17
|
+
this.sortedArray = undefined;
|
|
18
|
+
this.comp = comp;
|
|
19
|
+
}
|
|
20
|
+
_transform(data, _, callback) {
|
|
21
|
+
if (data) {
|
|
22
|
+
this.a[this.i++] = data;
|
|
23
|
+
if (this.i == this.currentSize) {
|
|
24
|
+
this.currentSize = this.currentSize * 2;
|
|
25
|
+
var tmp = new Array(this.currentSize);
|
|
26
|
+
for (var j = 0; j < this.i; j++) {
|
|
27
|
+
tmp[j] = this.a[j];
|
|
28
|
+
}
|
|
29
|
+
this.a = tmp;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
callback();
|
|
33
|
+
}
|
|
34
|
+
_flush() {
|
|
35
|
+
this.sortedArray = this.a.slice(0, this.i)
|
|
36
|
+
.sort(this.comp);
|
|
37
|
+
this.fullflush();
|
|
38
|
+
}
|
|
39
|
+
fullflush() {
|
|
40
|
+
while (this.k < this.i) {
|
|
41
|
+
this.push(this.sortedArray[this.k++]);
|
|
42
|
+
}
|
|
43
|
+
this.push(null);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const sort = (comp, options) => {
|
|
47
|
+
options = options || { objectMode: true };
|
|
48
|
+
return new SortStreamer(options, comp);
|
|
49
|
+
};
|
|
50
|
+
exports.default = sort;
|