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.
- package/.github/workflows/nodejs.yml +1 -1
- package/Gzip.js +24 -0
- package/Gzip.test.js +19 -0
- package/internal/StreamString.js +14 -0
- package/internal/StringStream.js +15 -0
- package/package.json +1 -1
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
|