Skip to content

Instantly share code, notes, and snippets.

@jmshal
Last active Jul 9, 2021
Embed
What would you like to do?
Node.js ponyfill for atob and btoa encoding functions
module.exports = function atob(a) {
return new Buffer(a, 'base64').toString('binary');
};
module.exports = function btoa(b) {
return new Buffer(b).toString('base64');
};
module.exports = {
atob: require('./atob'),
btoa: require('./btoa'),
};
{
"name": "atob-btoa.js",
"version": "1.0.0",
"description": "Node.js ponyfill for atob and btoa encoding functions"
}
@drveresh

This comment has been minimized.

Copy link

@drveresh drveresh commented Apr 28, 2020

The Buffer() is deprecated and is throwing the error "[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead"

@manuelbarzi

This comment has been minimized.

Copy link

@manuelbarzi manuelbarzi commented Jun 3, 2020

The Buffer() is deprecated and is throwing the error "[DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead"

this is not an error yet, but just a warning.

you can easily overcome it by updating the code as follows:

const atob = a => Buffer.from(a, 'base64').toString('binary')

const btoa = b => Buffer.from(b).toString('base64')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment