@middy/http-content-encoding 4.0.0 → 4.0.1

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/README.md CHANGED
@@ -36,66 +36,6 @@
36
36
  <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-content-encoding">https://middy.js.org/docs/middlewares/http-content-encoding</a></p>
37
37
  </div>
38
38
 
39
- This middleware take the `preferredEncoding` output from `@middy/http-content-negotiation` and applies the encoding to `response.body` when a string.
40
-
41
- ## Install
42
-
43
- To install this middleware you can use NPM:
44
-
45
- ```bash
46
- npm install --save @middy/http-content-encoding
47
- ```
48
-
49
- ## Options
50
- - `br` (object) (default `{}`): `zlib.createBrotliCompress` [brotliOptions](https://nodejs.org/api/zlib.html#zlib_class_brotlioptions)
51
- - `gzip` (object) (default `{}`): `zlib.createGzip` [gzipOptions](https://nodejs.org/api/zlib.html#zlib_class_options)
52
- - `deflate` (object) (default `{}`): `zlib.createDeflate` [deflateOptions](https://nodejs.org/api/zlib.html#zlib_class_options)
53
- - `overridePreferredEncoding` (array[string]) (optional): Override the preferred encoding order, most browsers prefer `gzip` over `br`, even though `br` has higher compression. Default: `[]`
54
-
55
- NOTES:
56
- - **Important** For `br` encoding NodeJS defaults to `11`. Levels `10` & `11` have been shown to have lower performance for the level of compression they apply. Testing is recommended to ensure the right balance of compression & performance.
57
-
58
- ## Sample usage
59
-
60
- ```javascript
61
- import middy from '@middy/core'
62
- import httpContentNegotiation from '@middy/http-content-negotiation'
63
- import httpContentEncoding from '@middy/http-content-encoding'
64
- import { constants } from 'zlib'
65
-
66
- const handler = middy((event, context) => {
67
- return {
68
- statusCode: 200,
69
- body: '{...}'
70
- }
71
- })
72
-
73
- handler
74
- .use(httpContentNegotiation())
75
- .use(httpCompressMiddleware({
76
- br: {
77
- params: {
78
- [constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT, // adjusted for UTF-8 text
79
- [constants.BROTLI_PARAM_QUALITY]: 7
80
- }
81
- },
82
- overridePreferredEncoding: ['br', 'gzip', 'deflate']
83
- }))
84
-
85
- export default { handler }
86
- ```
87
-
88
-
89
- ## Middy documentation and examples
90
-
91
- For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
92
-
93
-
94
- ## Contributing
95
-
96
- Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
97
-
98
-
99
39
  ## License
100
40
 
101
41
  Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
package/index.cjs CHANGED
@@ -41,10 +41,11 @@ const httpContentEncodingMiddleware = (opts)=>{
41
41
  break;
42
42
  }
43
43
  const stream = _nodeStream.Readable.from(response.body).pipe(contentEncodingStream);
44
- let body = '';
44
+ const chunks = [];
45
45
  for await (const chunk of stream){
46
- body += chunk;
46
+ chunks.push(chunk);
47
47
  }
48
+ const body = Buffer.concat(chunks).toString('base64');
48
49
  if (body.length < response.body.length) {
49
50
  response.headers['Content-Encoding'] = contentEncoding;
50
51
  response.body = body;
package/index.js CHANGED
@@ -33,10 +33,11 @@ const httpContentEncodingMiddleware = (opts)=>{
33
33
  break;
34
34
  }
35
35
  const stream = Readable.from(response.body).pipe(contentEncodingStream);
36
- let body = '';
36
+ const chunks = [];
37
37
  for await (const chunk of stream){
38
- body += chunk;
38
+ chunks.push(chunk);
39
39
  }
40
+ const body = Buffer.concat(chunks).toString('base64');
40
41
  if (body.length < response.body.length) {
41
42
  response.headers['Content-Encoding'] = contentEncoding;
42
43
  response.body = body;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-content-encoding",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Http content encoding middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -65,10 +65,10 @@
65
65
  },
66
66
  "homepage": "https://middy.js.org",
67
67
  "dependencies": {
68
- "@middy/util": "4.0.0"
68
+ "@middy/util": "4.0.1"
69
69
  },
70
70
  "devDependencies": {
71
- "@middy/core": "4.0.0"
71
+ "@middy/core": "4.0.1"
72
72
  },
73
- "gitHead": "582286144bcd79968a8c7c2f8867a23c80079a47"
73
+ "gitHead": "c5ece2bfbb0d607dcdea5685bf194a6cc19acc8d"
74
74
  }