@mavogel/awscdk-rootmail 0.0.218 → 0.0.220

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.
Files changed (99) hide show
  1. package/.jsii +4 -4
  2. package/lib/rootmail.js +1 -1
  3. package/lib/ses-receive.js +1 -1
  4. package/node_modules/cdk-nag/.jsii +2 -2
  5. package/node_modules/cdk-nag/lib/ignore-suppression-conditions.js +5 -5
  6. package/node_modules/cdk-nag/lib/nag-logger.js +2 -2
  7. package/node_modules/cdk-nag/lib/nag-pack.js +1 -1
  8. package/node_modules/cdk-nag/lib/nag-rules.js +1 -1
  9. package/node_modules/cdk-nag/lib/nag-suppressions.js +1 -1
  10. package/node_modules/cdk-nag/lib/packs/aws-solutions.js +1 -1
  11. package/node_modules/cdk-nag/lib/packs/hipaa-security.js +1 -1
  12. package/node_modules/cdk-nag/lib/packs/nist-800-53-r4.js +1 -1
  13. package/node_modules/cdk-nag/lib/packs/nist-800-53-r5.js +1 -1
  14. package/node_modules/cdk-nag/lib/packs/pci-dss-321.js +1 -1
  15. package/node_modules/cdk-nag/package.json +1 -1
  16. package/node_modules/encoding-japanese/README.md +65 -13
  17. package/node_modules/encoding-japanese/encoding.js +7 -2
  18. package/node_modules/encoding-japanese/encoding.min.js +2 -2
  19. package/node_modules/encoding-japanese/package.json +2 -2
  20. package/node_modules/encoding-japanese/src/encoding-convert.js +5 -0
  21. package/node_modules/libbase64/.prettierrc.js +4 -1
  22. package/node_modules/libbase64/lib/libbase64.js +2 -1
  23. package/node_modules/libbase64/package.json +9 -8
  24. package/node_modules/libmime/CHANGELOG.md +7 -0
  25. package/node_modules/libmime/package.json +5 -5
  26. package/node_modules/libqp/CHANGELOG.md +15 -0
  27. package/node_modules/libqp/lib/libqp.js +13 -21
  28. package/node_modules/libqp/package.json +7 -6
  29. package/node_modules/libqp/test/libqp-test.js +161 -0
  30. package/node_modules/mailparser/CHANGELOG.md +7 -0
  31. package/node_modules/mailparser/package.json +8 -8
  32. package/node_modules/mailsplit/LICENSE.MIT +6 -1
  33. package/node_modules/mailsplit/README.md +2 -0
  34. package/node_modules/mailsplit/lib/headers.js +5 -1
  35. package/node_modules/mailsplit/package.json +10 -9
  36. package/node_modules/nodemailer/.ncurc.js +4 -1
  37. package/node_modules/nodemailer/CHANGELOG.md +25 -0
  38. package/node_modules/nodemailer/lib/addressparser/index.js +22 -8
  39. package/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2 -0
  40. package/node_modules/nodemailer/lib/nodemailer.js +13 -6
  41. package/node_modules/nodemailer/lib/smtp-connection/index.js +9 -0
  42. package/node_modules/nodemailer/lib/well-known/services.json +14 -3
  43. package/node_modules/nodemailer/package.json +5 -5
  44. package/node_modules/tlds/index.json +0 -3
  45. package/node_modules/tlds/package.json +1 -1
  46. package/package.json +4 -4
  47. package/node_modules/libmime/node_modules/libbase64/.eslintrc +0 -11
  48. package/node_modules/libmime/node_modules/libbase64/.prettierrc.js +0 -8
  49. package/node_modules/libmime/node_modules/libbase64/LICENSE +0 -19
  50. package/node_modules/libmime/node_modules/libbase64/README.md +0 -113
  51. package/node_modules/libmime/node_modules/libbase64/lib/libbase64.js +0 -253
  52. package/node_modules/libmime/node_modules/libbase64/package.json +0 -35
  53. package/node_modules/libmime/node_modules/libqp/.eslintrc +0 -15
  54. package/node_modules/libmime/node_modules/libqp/.prettierrc.js +0 -8
  55. package/node_modules/libmime/node_modules/libqp/CHANGELOG.md +0 -8
  56. package/node_modules/libmime/node_modules/libqp/LICENSE +0 -19
  57. package/node_modules/libmime/node_modules/libqp/README.md +0 -119
  58. package/node_modules/libmime/node_modules/libqp/lib/libqp.js +0 -320
  59. package/node_modules/libmime/node_modules/libqp/package.json +0 -28
  60. package/node_modules/libmime/node_modules/libqp/test/libqp-test.js +0 -41
  61. package/node_modules/mailsplit/node_modules/encoding-japanese/LICENSE +0 -21
  62. package/node_modules/mailsplit/node_modules/encoding-japanese/README.md +0 -542
  63. package/node_modules/mailsplit/node_modules/encoding-japanese/encoding.js +0 -6077
  64. package/node_modules/mailsplit/node_modules/encoding-japanese/encoding.min.js +0 -8
  65. package/node_modules/mailsplit/node_modules/encoding-japanese/encoding.min.js.map +0 -1
  66. package/node_modules/mailsplit/node_modules/encoding-japanese/package.json +0 -70
  67. package/node_modules/mailsplit/node_modules/encoding-japanese/src/banner.js +0 -6
  68. package/node_modules/mailsplit/node_modules/encoding-japanese/src/config.js +0 -139
  69. package/node_modules/mailsplit/node_modules/encoding-japanese/src/encoding-convert.js +0 -1676
  70. package/node_modules/mailsplit/node_modules/encoding-japanese/src/encoding-detect.js +0 -502
  71. package/node_modules/mailsplit/node_modules/encoding-japanese/src/encoding-table.js +0 -4
  72. package/node_modules/mailsplit/node_modules/encoding-japanese/src/index.js +0 -593
  73. package/node_modules/mailsplit/node_modules/encoding-japanese/src/jis-to-utf8-table.js +0 -5
  74. package/node_modules/mailsplit/node_modules/encoding-japanese/src/jisx0212-to-utf8-table.js +0 -5
  75. package/node_modules/mailsplit/node_modules/encoding-japanese/src/kana-case-table.js +0 -41
  76. package/node_modules/mailsplit/node_modules/encoding-japanese/src/utf8-to-jis-table.js +0 -1493
  77. package/node_modules/mailsplit/node_modules/encoding-japanese/src/utf8-to-jisx0212-table.js +0 -1224
  78. package/node_modules/mailsplit/node_modules/encoding-japanese/src/util.js +0 -361
  79. package/node_modules/mailsplit/node_modules/libmime/.eslintrc +0 -7
  80. package/node_modules/mailsplit/node_modules/libmime/.gitattributes +0 -1
  81. package/node_modules/mailsplit/node_modules/libmime/.github/FUNDING.yml +0 -4
  82. package/node_modules/mailsplit/node_modules/libmime/.github/workflows/test.yml +0 -21
  83. package/node_modules/mailsplit/node_modules/libmime/.prettierrc.js +0 -8
  84. package/node_modules/mailsplit/node_modules/libmime/CHANGELOG.md +0 -110
  85. package/node_modules/mailsplit/node_modules/libmime/LICENSE +0 -19
  86. package/node_modules/mailsplit/node_modules/libmime/README.md +0 -207
  87. package/node_modules/mailsplit/node_modules/libmime/lib/charset.js +0 -117
  88. package/node_modules/mailsplit/node_modules/libmime/lib/charsets.js +0 -212
  89. package/node_modules/mailsplit/node_modules/libmime/lib/libmime.js +0 -903
  90. package/node_modules/mailsplit/node_modules/libmime/lib/mimetypes.js +0 -2049
  91. package/node_modules/mailsplit/node_modules/libmime/package.json +0 -37
  92. /package/node_modules/{libmime/node_modules/libbase64 → libbase64}/.github/FUNDING.yml +0 -0
  93. /package/node_modules/{libmime/node_modules/libbase64 → libbase64}/.github/workflows/release.yaml +0 -0
  94. /package/node_modules/{libmime/node_modules/libbase64 → libbase64}/.github/workflows/test.yml +0 -0
  95. /package/node_modules/{libmime/node_modules/libbase64 → libbase64}/.ncurc.js +0 -0
  96. /package/node_modules/{libmime/node_modules/libbase64 → libbase64}/CHANGELOG.md +0 -0
  97. /package/node_modules/{libmime/node_modules/libqp → libqp}/.github/FUNDING.yml +0 -0
  98. /package/node_modules/{libmime/node_modules/libqp → libqp}/.github/workflows/release.yaml +0 -0
  99. /package/node_modules/{libmime/node_modules/libqp → libqp}/.github/workflows/test.yml +0 -0
@@ -7,7 +7,6 @@
7
7
  * @return {Object} Address object
8
8
  */
9
9
  function _handleAddress(tokens) {
10
- let token;
11
10
  let isGroup = false;
12
11
  let state = 'text';
13
12
  let address;
@@ -23,7 +22,8 @@ function _handleAddress(tokens) {
23
22
 
24
23
  // Filter out <addresses>, (comments) and regular text
25
24
  for (i = 0, len = tokens.length; i < len; i++) {
26
- token = tokens[i];
25
+ let token = tokens[i];
26
+ let prevToken = i ? tokens[i - 1] : null;
27
27
  if (token.type === 'operator') {
28
28
  switch (token.value) {
29
29
  case '<':
@@ -38,6 +38,7 @@ function _handleAddress(tokens) {
38
38
  break;
39
39
  default:
40
40
  state = 'text';
41
+ break;
41
42
  }
42
43
  } else if (token.value) {
43
44
  if (state === 'address') {
@@ -46,7 +47,13 @@ function _handleAddress(tokens) {
46
47
  // and so will we
47
48
  token.value = token.value.replace(/^[^<]*<\s*/, '');
48
49
  }
49
- data[state].push(token.value);
50
+
51
+ if (prevToken && prevToken.noBreak && data[state].length) {
52
+ // join values
53
+ data[state][data[state].length - 1] += token.value;
54
+ } else {
55
+ data[state].push(token.value);
56
+ }
50
57
  }
51
58
  }
52
59
 
@@ -172,11 +179,12 @@ class Tokenizer {
172
179
  * @return {Array} An array of operator|text tokens
173
180
  */
174
181
  tokenize() {
175
- let chr,
176
- list = [];
182
+ let list = [];
183
+
177
184
  for (let i = 0, len = this.str.length; i < len; i++) {
178
- chr = this.str.charAt(i);
179
- this.checkChar(chr);
185
+ let chr = this.str.charAt(i);
186
+ let nextChr = i < len - 1 ? this.str.charAt(i + 1) : null;
187
+ this.checkChar(chr, nextChr);
180
188
  }
181
189
 
182
190
  this.list.forEach(node => {
@@ -194,7 +202,7 @@ class Tokenizer {
194
202
  *
195
203
  * @param {String} chr Character from the address field
196
204
  */
197
- checkChar(chr) {
205
+ checkChar(chr, nextChr) {
198
206
  if (this.escaped) {
199
207
  // ignore next condition blocks
200
208
  } else if (chr === this.operatorExpecting) {
@@ -202,10 +210,16 @@ class Tokenizer {
202
210
  type: 'operator',
203
211
  value: chr
204
212
  };
213
+
214
+ if (nextChr && ![' ', '\t', '\r', '\n', ',', ';'].includes(nextChr)) {
215
+ this.node.noBreak = true;
216
+ }
217
+
205
218
  this.list.push(this.node);
206
219
  this.node = null;
207
220
  this.operatorExpecting = '';
208
221
  this.escaped = false;
222
+
209
223
  return;
210
224
  } else if (!this.operatorExpecting && chr in this.operators) {
211
225
  this.node = {
@@ -44,6 +44,7 @@ const mimeTypes = new Map([
44
44
  ['application/fractals', 'fif'],
45
45
  ['application/freeloader', 'frl'],
46
46
  ['application/futuresplash', 'spl'],
47
+ ['application/geo+json', 'geojson'],
47
48
  ['application/gnutar', 'tgz'],
48
49
  ['application/groupwise', 'vew'],
49
50
  ['application/hlp', 'hlp'],
@@ -1287,6 +1288,7 @@ const extensions = new Map([
1287
1288
  ['gac', 'application/vnd.groove-account'],
1288
1289
  ['gdl', 'model/vnd.gdl'],
1289
1290
  ['geo', 'application/vnd.dynageo'],
1291
+ ['geojson', 'application/geo+json'],
1290
1292
  ['gex', 'application/vnd.geometry-explorer'],
1291
1293
  ['ggb', 'application/vnd.geogebra.file'],
1292
1294
  ['ggt', 'application/vnd.geogebra.tool'],
@@ -13,6 +13,7 @@ const packageData = require('../package.json');
13
13
 
14
14
  const ETHEREAL_API = (process.env.ETHEREAL_API || 'https://api.nodemailer.com').replace(/\/+$/, '');
15
15
  const ETHEREAL_WEB = (process.env.ETHEREAL_WEB || 'https://ethereal.email').replace(/\/+$/, '');
16
+ const ETHEREAL_API_KEY = (process.env.ETHEREAL_API_KEY || '').replace(/\s*/g, '') || null;
16
17
  const ETHEREAL_CACHE = ['true', 'yes', 'y', '1'].includes((process.env.ETHEREAL_CACHE || 'yes').toString().trim().toLowerCase());
17
18
 
18
19
  let testAccount = false;
@@ -79,15 +80,21 @@ module.exports.createTestAccount = function (apiUrl, callback) {
79
80
  let chunks = [];
80
81
  let chunklen = 0;
81
82
 
83
+ let requestHeaders = {};
84
+ let requestBody = {
85
+ requestor: packageData.name,
86
+ version: packageData.version
87
+ };
88
+
89
+ if (ETHEREAL_API_KEY) {
90
+ requestHeaders.Authorization = 'Bearer ' + ETHEREAL_API_KEY;
91
+ }
92
+
82
93
  let req = nmfetch(apiUrl + '/user', {
83
94
  contentType: 'application/json',
84
95
  method: 'POST',
85
- body: Buffer.from(
86
- JSON.stringify({
87
- requestor: packageData.name,
88
- version: packageData.version
89
- })
90
- )
96
+ headers: requestHeaders,
97
+ body: Buffer.from(JSON.stringify(requestBody))
91
98
  });
92
99
 
93
100
  req.on('readable', () => {
@@ -628,6 +628,15 @@ class SMTPConnection extends EventEmitter {
628
628
  let startTime = Date.now();
629
629
  this._setEnvelope(envelope, (err, info) => {
630
630
  if (err) {
631
+ // create passthrough stream to consume to prevent OOM
632
+ let stream = new PassThrough();
633
+ if (typeof message.pipe === 'function') {
634
+ message.pipe(stream);
635
+ } else {
636
+ stream.write(message);
637
+ stream.end();
638
+ }
639
+
631
640
  return callback(err);
632
641
  }
633
642
  let envelopeTime = Date.now();
@@ -57,6 +57,14 @@
57
57
  "secure": true
58
58
  },
59
59
 
60
+ "Feishu Mail": {
61
+ "aliases": ["Feishu", "FeishuMail"],
62
+ "domains": ["www.feishu.cn"],
63
+ "host": "smtp.feishu.cn",
64
+ "port": 465,
65
+ "secure": true
66
+ },
67
+
60
68
  "GandiMail": {
61
69
  "aliases": ["Gandi", "Gandi Mail"],
62
70
  "host": "mail.gandi.net",
@@ -109,7 +117,10 @@
109
117
  "domains": ["ik.me", "ikmail.com", "etik.com"],
110
118
  "port": 587
111
119
  },
112
-
120
+ "Loopia": {
121
+ "host": "mailcluster.loopia.se",
122
+ "port": 465
123
+ },
113
124
  "mail.ee": {
114
125
  "host": "smtp.mail.ee"
115
126
  },
@@ -147,8 +158,8 @@
147
158
  },
148
159
 
149
160
  "Mailtrap": {
150
- "host": "smtp.mailtrap.io",
151
- "port": 2525
161
+ "host": "live.smtp.mailtrap.io",
162
+ "port": 587
152
163
  },
153
164
 
154
165
  "Mandrill": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodemailer",
3
- "version": "6.9.13",
3
+ "version": "6.9.16",
4
4
  "description": "Easy as cake e-mail sending from your Node.js applications",
5
5
  "main": "lib/nodemailer.js",
6
6
  "scripts": {
@@ -23,19 +23,19 @@
23
23
  },
24
24
  "homepage": "https://nodemailer.com/",
25
25
  "devDependencies": {
26
- "@aws-sdk/client-ses": "3.529.1",
26
+ "@aws-sdk/client-ses": "3.679.0",
27
27
  "bunyan": "1.8.15",
28
- "c8": "9.1.0",
28
+ "c8": "10.1.2",
29
29
  "eslint": "8.57.0",
30
30
  "eslint-config-nodemailer": "1.2.0",
31
31
  "eslint-config-prettier": "9.1.0",
32
32
  "libbase64": "1.3.0",
33
- "libmime": "5.3.4",
33
+ "libmime": "5.3.5",
34
34
  "libqp": "2.1.0",
35
35
  "nodemailer-ntlm-auth": "1.0.4",
36
36
  "proxy": "1.0.2",
37
37
  "proxy-test-server": "1.0.0",
38
- "smtp-server": "3.13.3"
38
+ "smtp-server": "3.13.6"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=6.0.0"
@@ -297,7 +297,6 @@
297
297
  "cymru",
298
298
  "cyou",
299
299
  "cz",
300
- "dabur",
301
300
  "dad",
302
301
  "dance",
303
302
  "data",
@@ -802,7 +801,6 @@
802
801
  "nab",
803
802
  "nagoya",
804
803
  "name",
805
- "natura",
806
804
  "navy",
807
805
  "nba",
808
806
  "nc",
@@ -1039,7 +1037,6 @@
1039
1037
  "sh",
1040
1038
  "shangrila",
1041
1039
  "sharp",
1042
- "shaw",
1043
1040
  "shell",
1044
1041
  "shia",
1045
1042
  "shiksha",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tlds",
3
- "version": "1.252.0",
3
+ "version": "1.255.0",
4
4
  "description": "A list of TLDs.",
5
5
  "repository": "https://github.com/stephenmathieson/node-tlds.git",
6
6
  "author": "Stephen Mathieson",
package/package.json CHANGED
@@ -56,7 +56,7 @@
56
56
  "@typescript-eslint/eslint-plugin": "^8",
57
57
  "@typescript-eslint/parser": "^8",
58
58
  "aws-cdk-lib": "2.90.0",
59
- "cdk-assets": "^2.155.45",
59
+ "cdk-assets": "^2.155.47",
60
60
  "commit-and-tag-version": "^12",
61
61
  "constructs": "10.0.5",
62
62
  "eslint": "^9",
@@ -88,8 +88,8 @@
88
88
  "@aws-sdk/client-ssm": "^3.699.0",
89
89
  "async-retry": "^1.3.3",
90
90
  "axios": "^1.7.8",
91
- "cdk-nag": "^2.34.9",
92
- "mailparser": "^3.7.1",
91
+ "cdk-nag": "^2.34.11",
92
+ "mailparser": "^3.7.2",
93
93
  "uuid": "^9.0.1"
94
94
  },
95
95
  "bundledDependencies": [
@@ -116,7 +116,7 @@
116
116
  "publishConfig": {
117
117
  "access": "public"
118
118
  },
119
- "version": "0.0.218",
119
+ "version": "0.0.220",
120
120
  "jest": {
121
121
  "coverageProvider": "v8",
122
122
  "testMatch": [
@@ -1,11 +0,0 @@
1
- {
2
- "rules": {
3
- "indent": 0,
4
- "global-require": 0,
5
- "no-await-in-loop": 0
6
- },
7
- "extends": ["nodemailer", "prettier"],
8
- "parserOptions": {
9
- "ecmaVersion": 2017
10
- }
11
- }
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- printWidth: 160,
3
- tabWidth: 4,
4
- singleQuote: true,
5
- endOfLine: 'lf',
6
- trailingComma: 'none',
7
- arrowParens: 'avoid'
8
- };
@@ -1,19 +0,0 @@
1
- Copyright (c) 2014-2017 Andris Reinman
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
@@ -1,113 +0,0 @@
1
- # libbase64
2
-
3
- Encode and decode base64 strings.
4
-
5
- ## Usage
6
-
7
- Install with npm
8
-
9
- npm install libbase64
10
-
11
- Require in your script
12
-
13
- ```javascript
14
- const libbase64 = require('libbase64');
15
- ```
16
-
17
- ### Encode values
18
-
19
- Encode Buffer objects or unicode strings with
20
-
21
- libbase64.encode(val) → String
22
-
23
- Where
24
-
25
- - **val** is a Buffer or an unicode string
26
-
27
- **Example**
28
-
29
- ```javascript
30
- libbase64.encode('jõgeva');
31
- // asO1Z2V2YQ==
32
- ```
33
-
34
- ### Wrap encoded values
35
-
36
- To enforce soft line breaks on lines longer than selected amount of characters, use `wrap`
37
-
38
- libbase64.wrap(str[, lineLength]) → String
39
-
40
- Where
41
-
42
- - **str** is a base64 encoded string
43
- - **lineLength** (defaults to 76) is the maximum allowed line length
44
-
45
- **Example**
46
-
47
- ```javascript
48
- libbase64.wrap('asO1Z2V2asO1Z2V2asO1Z2V2YQ==', 10);
49
- // asO1Z2V2as\r\n
50
- // O1Z2V2asO1\r\n
51
- // Z2V2YQ==
52
- ```
53
-
54
- ### Transform Streams
55
-
56
- `libbase64` makes it possible to encode and decode streams with `libbase64.Encoder` and `libbase64.Decoder` constructors.
57
-
58
- ### Encoder Stream
59
-
60
- Create new Encoder Stream with
61
-
62
- const encoder = new libbase64.Encoder([options])
63
-
64
- Where
65
-
66
- - **options** is the optional stream options object
67
- - **options.lineLength** (Number) if you want to use any other line length than the default 76
68
- characters (or set to `false` to turn the soft wrapping off completely)
69
- - **options.skipStartBytes** (Number) Optional. How many bytes to skip from output (default to 0)
70
- - **options.limitOutbutBytes** (Number) Optional. How many bytes to return (defaults to all bytes)
71
- - **options.startPadding** (String) Optional. Fills first line with provided padding string. Usually goes together with skipStartBytes to get line folding correct.
72
-
73
- **Example**
74
-
75
- The following example script reads in a file, encodes it to base64 and saves the output to a file.
76
-
77
- ```javascript
78
- const libbase64 = require('libbase64');
79
- const fs = require('fs');
80
- const source = fs.createReadStream('source.txt');
81
- const encoded = fs.createReadStream('encoded.txt');
82
- const encoder = new libbase64.Encoder();
83
-
84
- source.pipe(encoder).pipe(encoded);
85
- ```
86
-
87
- ### Decoder Stream
88
-
89
- Create new Decoder Stream with
90
-
91
- const decoder = new libbase64.Decoder([options])
92
-
93
- Where
94
-
95
- - **options** is the optional stream options object
96
-
97
- **Example**
98
-
99
- The following example script reads in a file in base64 encoding, decodes it and saves the output to a file.
100
-
101
- ```javascript
102
- const libbase64 = require('libbase64');
103
- const fs = require('fs');
104
- const encoded = fs.createReadStream('encoded.txt');
105
- const dest = fs.createReadStream('dest.txt');
106
- const decoder = new libbase64.Decoder();
107
-
108
- encoded.pipe(decoder).pipe(dest);
109
- ```
110
-
111
- ## License
112
-
113
- **MIT**
@@ -1,253 +0,0 @@
1
- 'use strict';
2
-
3
- const { Buffer } = require('node:buffer');
4
- const stream = require('node:stream');
5
- const Transform = stream.Transform;
6
-
7
- /**
8
- * Encodes a Buffer into a base64 encoded string
9
- *
10
- * @param {Buffer} buffer Buffer to convert
11
- * @returns {String} base64 encoded string
12
- */
13
- function encode(buffer) {
14
- if (typeof buffer === 'string') {
15
- buffer = Buffer.from(buffer, 'utf-8');
16
- }
17
-
18
- return buffer.toString('base64');
19
- }
20
-
21
- /**
22
- * Decodes a base64 encoded string to a Buffer object
23
- *
24
- * @param {String} str base64 encoded string
25
- * @returns {Buffer} Decoded value
26
- */
27
- function decode(str) {
28
- str = str || '';
29
- return Buffer.from(str, 'base64');
30
- }
31
-
32
- /**
33
- * Adds soft line breaks to a base64 string
34
- *
35
- * @param {String} str base64 encoded string that might need line wrapping
36
- * @param {Number} [lineLength=76] Maximum allowed length for a line
37
- * @returns {String} Soft-wrapped base64 encoded string
38
- */
39
- function wrap(str, lineLength) {
40
- str = (str || '').toString();
41
- lineLength = lineLength || 76;
42
-
43
- if (str.length <= lineLength) {
44
- return str;
45
- }
46
-
47
- let result = [];
48
- let pos = 0;
49
- let chunkLength = lineLength * 1024;
50
- while (pos < str.length) {
51
- let wrappedLines = str
52
- .substr(pos, chunkLength)
53
- .replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n')
54
- .trim();
55
- result.push(wrappedLines);
56
- pos += chunkLength;
57
- }
58
-
59
- return result.join('\r\n').trim();
60
- }
61
-
62
- /**
63
- * Creates a transform stream for encoding data to base64 encoding
64
- *
65
- * @constructor
66
- * @param {Object} options Stream options
67
- * @param {Number} [options.lineLength=76] Maximum lenght for lines, set to false to disable wrapping
68
- */
69
- class Encoder extends Transform {
70
- constructor(options) {
71
- super();
72
- // init Transform
73
- this.options = options || {};
74
-
75
- if (this.options.lineLength !== false) {
76
- this.options.lineLength = Number(this.options.lineLength) || 76;
77
- }
78
-
79
- this.skipStartBytes = Number(this.options.skipStartBytes) || 0;
80
- this.limitOutbutBytes = Number(this.options.limitOutbutBytes) || 0;
81
-
82
- // startPadding can be used together with skipStartBytes
83
- this._curLine = this.options.startPadding || '';
84
- this._remainingBytes = false;
85
-
86
- this.inputBytes = 0;
87
- this.outputBytes = 0;
88
- }
89
-
90
- _writeChunk(chunk /*, isFinal */) {
91
- if (this.skipStartBytes) {
92
- if (chunk.length <= this.skipStartBytes) {
93
- this.skipStartBytes -= chunk.length;
94
- return;
95
- }
96
-
97
- chunk = chunk.slice(this.skipStartBytes);
98
- this.skipStartBytes = 0;
99
- }
100
-
101
- if (this.limitOutbutBytes) {
102
- if (this.outputBytes + chunk.length <= this.limitOutbutBytes) {
103
- // ignore, can use entire chunk
104
- } else if (this.outputBytes >= this.limitOutbutBytes) {
105
- // chunks already processed
106
- return;
107
- } else {
108
- // use partial chunk
109
- chunk = chunk.slice(0, this.limitOutbutBytes - this.outputBytes);
110
- }
111
- }
112
-
113
- this.outputBytes += chunk.length;
114
- this.push(chunk);
115
- }
116
-
117
- _getWrapped(str, isFinal) {
118
- str = wrap(str, this.options.lineLength);
119
- if (!isFinal && str.length === this.options.lineLength) {
120
- str += '\r\n';
121
- }
122
- return str;
123
- }
124
-
125
- _transform(chunk, encoding, done) {
126
- if (encoding !== 'buffer') {
127
- chunk = Buffer.from(chunk, encoding);
128
- }
129
-
130
- if (!chunk || !chunk.length) {
131
- return setImmediate(done);
132
- }
133
-
134
- this.inputBytes += chunk.length;
135
-
136
- if (this._remainingBytes && this._remainingBytes.length) {
137
- chunk = Buffer.concat([this._remainingBytes, chunk], this._remainingBytes.length + chunk.length);
138
- this._remainingBytes = false;
139
- }
140
-
141
- if (chunk.length % 3) {
142
- this._remainingBytes = chunk.slice(chunk.length - (chunk.length % 3));
143
- chunk = chunk.slice(0, chunk.length - (chunk.length % 3));
144
- } else {
145
- this._remainingBytes = false;
146
- }
147
-
148
- let b64 = this._curLine + encode(chunk);
149
-
150
- if (this.options.lineLength) {
151
- b64 = this._getWrapped(b64);
152
-
153
- // remove last line as it is still most probably incomplete
154
- let lastLF = b64.lastIndexOf('\n');
155
- if (lastLF < 0) {
156
- this._curLine = b64;
157
- b64 = '';
158
- } else if (lastLF === b64.length - 1) {
159
- this._curLine = '';
160
- } else {
161
- this._curLine = b64.substr(lastLF + 1);
162
- b64 = b64.substr(0, lastLF + 1);
163
- }
164
- }
165
-
166
- if (b64) {
167
- this._writeChunk(Buffer.from(b64, 'ascii'), false);
168
- }
169
-
170
- setImmediate(done);
171
- }
172
-
173
- _flush(done) {
174
- if (this._remainingBytes && this._remainingBytes.length) {
175
- this._curLine += encode(this._remainingBytes);
176
- }
177
-
178
- if (this._curLine) {
179
- this._curLine = this._getWrapped(this._curLine, true);
180
- this._writeChunk(Buffer.from(this._curLine, 'ascii'), true);
181
- this._curLine = '';
182
- }
183
- done();
184
- }
185
- }
186
-
187
- /**
188
- * Creates a transform stream for decoding base64 encoded strings
189
- *
190
- * @constructor
191
- * @param {Object} options Stream options
192
- */
193
- class Decoder extends Transform {
194
- constructor(options) {
195
- super();
196
- // init Transform
197
- this.options = options || {};
198
- this._curLine = '';
199
-
200
- this.inputBytes = 0;
201
- this.outputBytes = 0;
202
- }
203
-
204
- _transform(chunk, encoding, done) {
205
- if (!chunk || !chunk.length) {
206
- return setImmediate(done);
207
- }
208
-
209
- this.inputBytes += chunk.length;
210
-
211
- let b64 = this._curLine + chunk.toString('ascii');
212
- this._curLine = '';
213
-
214
- if (/[^a-zA-Z0-9+/=]/.test(b64)) {
215
- b64 = b64.replace(/[^a-zA-Z0-9+/=]/g, '');
216
- }
217
-
218
- if (b64.length < 4) {
219
- this._curLine = b64;
220
- b64 = '';
221
- } else if (b64.length % 4) {
222
- this._curLine = b64.substr(-b64.length % 4);
223
- b64 = b64.substr(0, b64.length - this._curLine.length);
224
- }
225
-
226
- if (b64) {
227
- let buf = decode(b64);
228
- this.outputBytes += buf.length;
229
- this.push(buf);
230
- }
231
-
232
- setImmediate(done);
233
- }
234
-
235
- _flush(done) {
236
- if (this._curLine) {
237
- let buf = decode(this._curLine);
238
- this.outputBytes += buf.length;
239
- this.push(buf);
240
- this._curLine = '';
241
- }
242
- setImmediate(done);
243
- }
244
- }
245
-
246
- // expose to the world
247
- module.exports = {
248
- encode,
249
- decode,
250
- wrap,
251
- Encoder,
252
- Decoder
253
- };