Skip to content

Commit c4545f0

Browse files
committed
v0.2.0
1 parent 7b159a6 commit c4545f0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lib/libbase64.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
*/
2222
function encode(buffer) {
2323
if (typeof buffer === 'string') {
24-
buffer = new Buffer(buffer, 'utf-8');
24+
buffer = Buffer.from(buffer, 'utf-8');
2525
}
2626

2727
return buffer.toString('base64');
@@ -34,8 +34,8 @@ function encode(buffer) {
3434
* @returns {Buffer} Decoded value
3535
*/
3636
function decode(str) {
37-
str = (str || '');
38-
return new Buffer(str, 'base64');
37+
str = str || '';
38+
return Buffer.from(str, 'base64');
3939
}
4040

4141
/**
@@ -82,10 +82,11 @@ function Encoder(options) {
8282
util.inherits(Encoder, Transform);
8383

8484
Encoder.prototype._transform = function(chunk, encoding, done) {
85-
var b64, _self = this;
85+
var b64,
86+
_self = this;
8687

8788
if (encoding !== 'buffer') {
88-
chunk = new Buffer(chunk, encoding);
89+
chunk = Buffer.from(chunk, encoding);
8990
}
9091

9192
if (!chunk || !chunk.length) {
@@ -166,14 +167,15 @@ Decoder.prototype._transform = function(chunk, encoding, done) {
166167

167168
this.inputBytes += chunk.length;
168169

169-
b64 = (this._curLine + chunk);
170+
b64 = this._curLine + chunk;
170171
this._curLine = '';
171172

172173
b64 = b64.replace(/[^a-zA-Z0-9+\/=]/g, '');
173174

174175
if (b64.length % 4) {
175176
this._curLine = b64.substr(-b64.length % 4);
176-
if (this._curLine.length == b64.length) {
177+
if (this._curLine.length == b64.length || this._curLine.length < 4) {
178+
this._curLine = b64;
177179
b64 = '';
178180
} else {
179181
b64 = b64.substr(0, this._curLine.length);
@@ -198,4 +200,4 @@ Decoder.prototype._flush = function(done) {
198200
this._curLine = '';
199201
}
200202
done();
201-
};
203+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libbase64",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Encode and decode base64 encoded strings",
55
"main": "lib/libbase64.js",
66
"scripts": {
@@ -26,4 +26,4 @@
2626
"grunt-contrib-jshint": "~0.8.0",
2727
"grunt-mocha-test": "~0.10.0"
2828
}
29-
}
29+
}

0 commit comments

Comments
 (0)