Skip to content

Commit 86ee2a6

Browse files
committed
v1.2.0
1 parent cd8813a commit 86ee2a6

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: node_js
22
node_js:
3-
- 6
4-
- 8
5-
- 9
3+
- 8
4+
- 10
5+
- 12
66
before_install:
7-
- npm install -g grunt-cli
7+
- npm install -g grunt-cli
88
notifications:
9-
email:
10-
9+
email:
10+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Where
6868
characters (or set to `false` to turn the soft wrapping off completely)
6969
- **options.skipStartBytes** (Number) Optional. How many bytes to skip from output (default to 0)
7070
- **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.
7172

7273
**Example**
7374

lib/libbase64.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ class Encoder extends Transform {
7272
this.options = options || {};
7373

7474
if (this.options.lineLength !== false) {
75-
this.options.lineLength = this.options.lineLength || 76;
75+
this.options.lineLength = Number(this.options.lineLength) || 76;
7676
}
7777

78-
this.skipStartBytes = this.options.skipStartBytes || 0;
79-
this.limitOutbutBytes = this.options.limitOutbutBytes || 0;
78+
this.skipStartBytes = Number(this.options.skipStartBytes) || 0;
79+
this.limitOutbutBytes = Number(this.options.limitOutbutBytes) || 0;
8080

81-
this._curLine = '';
81+
// startPadding can be used together with skipStartBytes
82+
this._curLine = this.options.startPadding || '';
8283
this._remainingBytes = false;
8384

8485
this.inputBytes = 0;
@@ -112,6 +113,18 @@ class Encoder extends Transform {
112113
this.push(chunk);
113114
}
114115

116+
_getWrapped(str) {
117+
let prefix = '';
118+
119+
str = wrap(str, this.options.lineLength);
120+
121+
if (prefix) {
122+
str = prefix + str;
123+
}
124+
125+
return str;
126+
}
127+
115128
_transform(chunk, encoding, done) {
116129
if (encoding !== 'buffer') {
117130
chunk = Buffer.from(chunk, encoding);
@@ -138,7 +151,7 @@ class Encoder extends Transform {
138151
let b64 = this._curLine + encode(chunk);
139152

140153
if (this.options.lineLength) {
141-
b64 = wrap(b64, this.options.lineLength);
154+
b64 = this._getWrapped(b64);
142155

143156
// remove last line as it is still most probably incomplete
144157
let lastLF = b64.lastIndexOf('\n');
@@ -166,7 +179,7 @@ class Encoder extends Transform {
166179
}
167180

168181
if (this._curLine) {
169-
this._curLine = wrap(this._curLine, this.options.lineLength);
182+
this._curLine = this._getWrapped(this._curLine);
170183
this._writeChunk(Buffer.from(this._curLine, 'ascii'), true);
171184
this._curLine = '';
172185
}

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libbase64",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Encode and decode base64 encoded strings",
55
"main": "lib/libbase64.js",
66
"scripts": {
@@ -21,14 +21,14 @@
2121
},
2222
"homepage": "https://github.com/nodemailer/libbase64",
2323
"devDependencies": {
24-
"chai": "^4.2.0",
25-
"eslint-config-nodemailer": "^1.2.0",
26-
"eslint-config-prettier": "^6.0.0",
27-
"grunt": "^1.0.4",
28-
"grunt-cli": "^1.3.2",
29-
"grunt-eslint": "^22.0.0",
30-
"grunt-mocha-test": "^0.13.3",
31-
"mocha": "^6.2.0"
24+
"chai": "4.2.0",
25+
"eslint-config-nodemailer": "1.2.0",
26+
"eslint-config-prettier": "6.0.0",
27+
"grunt": "1.0.4",
28+
"grunt-cli": "1.3.2",
29+
"grunt-eslint": "22.0.0",
30+
"grunt-mocha-test": "0.13.3",
31+
"mocha": "6.2.0"
3232
},
3333
"dependencies": {}
3434
}

0 commit comments

Comments
 (0)