presidium 0.16.21 → 0.16.22

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.
@@ -67,7 +67,7 @@ jobs:
67
67
 
68
68
  strategy:
69
69
  matrix:
70
- node-version: [14.x, 15.x, 16.x, 17.x]
70
+ node-version: [15.x, 16.x, 17.x, 18.x]
71
71
 
72
72
  steps:
73
73
  - uses: actions/checkout@v2
package/Gzip.js ADDED
@@ -0,0 +1,24 @@
1
+ const zlib = require('zlib')
2
+ const StringStream = require('./internal/StringStream')
3
+
4
+ /**
5
+ * @name Gzip
6
+ *
7
+ * @synopsis
8
+ * ```coffeescript [specscript]
9
+ * Gzip(raw string) -> gzip stream
10
+ * ```
11
+ *
12
+ * @description
13
+ * ```js
14
+ * const data = { a: 1 }
15
+ *
16
+ * Gzip(JSON.stringify(data)).pipe(response)
17
+ * ```
18
+ */
19
+
20
+ const Gzip = function (raw) {
21
+ return StringStream(raw).pipe(zlib.createGzip())
22
+ }
23
+
24
+ module.exports = Gzip
package/Gzip.test.js ADDED
@@ -0,0 +1,19 @@
1
+ const Test = require('thunk-test')
2
+ const assert = require('assert')
3
+ const zlib = require('zlib')
4
+ const Gzip = require('./Gzip')
5
+ const StreamString = require('./internal/StreamString')
6
+
7
+ const test = new Test('Gzip', async function () {
8
+ const raw = 'aaaaabbbbbbbcccc'
9
+ const transformed = await StreamString(
10
+ Gzip(raw).pipe(zlib.createGunzip())
11
+ )
12
+ assert.equal(raw, transformed)
13
+ }).case()
14
+
15
+ if (process.argv[1] == __filename) {
16
+ test()
17
+ }
18
+
19
+ module.exports = test
@@ -0,0 +1,14 @@
1
+ // stream Readable => str string
2
+ const StreamString = function (stream) {
3
+ return new Promise(resolve => {
4
+ let str = ''
5
+ stream.on('data', chunk => {
6
+ str += chunk
7
+ })
8
+ stream.on('end', () => {
9
+ resolve(str)
10
+ })
11
+ })
12
+ }
13
+
14
+ module.exports = StreamString
@@ -0,0 +1,15 @@
1
+ const { Readable } = require('stream')
2
+
3
+ /**
4
+ * @name StringStream
5
+ *
6
+ * @synopsis
7
+ * ```coffeescript [specscript]
8
+ * StringStream(str string)
9
+ * ```
10
+ */
11
+ const StringStream = function (str) {
12
+ return Readable.from([str])
13
+ }
14
+
15
+ module.exports = StringStream
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.16.21",
3
+ "version": "0.16.22",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",