Skip to content

Commit d042ef1

Browse files
authored
chore: es6 base64 parser (cloudevents#75)
Signed-off-by: Grant Timmerman <[email protected]>
1 parent 6c223e2 commit d042ef1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/formats/base64.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
class Base64Parser {
2+
constructor(decorator) {
3+
this.decorator = decorator;
4+
}
15

2-
function Parser(decorator) {
3-
this.decorator = decorator;
4-
}
6+
parse(payload) {
7+
let payloadToParse = payload;
8+
if (this.decorator) {
9+
payloadToParse = this.decorator.parse(payload);
10+
}
511

6-
Parser.prototype.parse = function(payload) {
7-
let toparse = payload;
8-
if (this.decorator) {
9-
toparse = this.decorator.parse(payload);
12+
return Buffer.from(payloadToParse, "base64").toString();
1013
}
14+
}
1115

12-
return Buffer.from(toparse, "base64").toString();
13-
};
14-
15-
module.exports = Parser;
16+
module.exports = Base64Parser;

0 commit comments

Comments
 (0)