libbase64
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -71,3 +71,2 @@ 'use strict'; | ||
super(); | ||
// init Transform | ||
@@ -80,2 +79,5 @@ this.options = options || {}; | ||
this.skipStartBytes = this.options.skipStartBytes || 0; | ||
this.limitOutbutBytes = this.options.limitOutbutBytes || 0; | ||
this._curLine = ''; | ||
@@ -88,2 +90,29 @@ this._remainingBytes = false; | ||
_writeChunk(chunk /*, isFinal */) { | ||
if (this.skipStartBytes) { | ||
if (chunk.length <= this.skipStartBytes) { | ||
this.skipStartBytes -= chunk.length; | ||
return; | ||
} | ||
chunk = chunk.slice(this.skipStartBytes); | ||
this.skipStartBytes = 0; | ||
} | ||
if (this.limitOutbutBytes) { | ||
if (this.outputBytes + chunk.length <= this.limitOutbutBytes) { | ||
// ignore, can use entire chunk | ||
} else if (this.outputBytes >= this.limitOutbutBytes) { | ||
// chunks already processed | ||
return; | ||
} else { | ||
// use partial chunk | ||
chunk = chunk.slice(0, this.limitOutbutBytes - this.outputBytes); | ||
} | ||
} | ||
this.outputBytes += chunk.length; | ||
this.push(chunk); | ||
} | ||
_transform(chunk, encoding, done) { | ||
@@ -106,4 +135,4 @@ if (encoding !== 'buffer') { | ||
if (chunk.length % 3) { | ||
this._remainingBytes = chunk.slice(chunk.length - chunk.length % 3); | ||
chunk = chunk.slice(0, chunk.length - chunk.length % 3); | ||
this._remainingBytes = chunk.slice(chunk.length - (chunk.length % 3)); | ||
chunk = chunk.slice(0, chunk.length - (chunk.length % 3)); | ||
} else { | ||
@@ -132,4 +161,3 @@ this._remainingBytes = false; | ||
if (b64) { | ||
this.outputBytes += b64.length; | ||
this.push(Buffer.from(b64, 'ascii')); | ||
this._writeChunk(Buffer.from(b64, 'ascii'), false); | ||
} | ||
@@ -144,9 +172,9 @@ | ||
} | ||
if (this._curLine) { | ||
this._curLine = wrap(this._curLine, this.options.lineLength); | ||
this.outputBytes += this._curLine.length; | ||
this.push(Buffer.from(this._curLine, 'ascii')); | ||
this._writeChunk(Buffer.from(this._curLine, 'ascii'), true); | ||
this._curLine = ''; | ||
} | ||
setImmediate(done); | ||
done(); | ||
} | ||
@@ -153,0 +181,0 @@ } |
{ | ||
"name": "libbase64", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Encode and decode base64 encoded strings", | ||
@@ -24,11 +24,12 @@ "main": "lib/libbase64.js", | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"chai": "^4.2.0", | ||
"eslint-config-nodemailer": "^1.2.0", | ||
"grunt": "^1.0.3", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-eslint": "^21.0.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"grunt": "^1.0.4", | ||
"grunt-cli": "^1.3.2", | ||
"grunt-eslint": "^22.0.0", | ||
"grunt-mocha-test": "^0.13.3", | ||
"mocha": "^5.2.0" | ||
"mocha": "^6.2.0" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -25,3 +25,3 @@ # libbase64 | ||
* **val** is a Buffer or an unicode string | ||
- **val** is a Buffer or an unicode string | ||
@@ -43,4 +43,4 @@ **Example** | ||
* **str** is a base64 encoded string | ||
* **lineLength** (defaults to 76) is the maximum allowed line length | ||
- **str** is a base64 encoded string | ||
- **lineLength** (defaults to 76) is the maximum allowed line length | ||
@@ -68,4 +68,7 @@ **Example** | ||
* **options** is the optional stream options object with an additional option `lineLength` if you want to use any other line length than the default 76 | ||
characters (or set to `false` to turn the soft wrapping off completely) | ||
- **options** is the optional stream options object | ||
- **options.lineLength** (Number) if you want to use any other line length than the default 76 | ||
characters (or set to `false` to turn the soft wrapping off completely) | ||
- **options.skipStartBytes** (Number) Optional. How many bytes to skip from output (default to 0) | ||
- **options.limitOutbutBytes** (Number) Optional. How many bytes to return (defaults to all bytes) | ||
@@ -94,3 +97,3 @@ **Example** | ||
* **options** is the optional stream options object | ||
- **options** is the optional stream options object | ||
@@ -97,0 +100,0 @@ **Example** |
Sorry, the diff of this file is not supported yet
11176
6
208
113
8