Skip to content

Instantly share code, notes, and snippets.

@jmshal
Last active April 27, 2024 04:12
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jmshal/b14199f7402c8f3a4568733d8bed0f25 to your computer and use it in GitHub Desktop.
Save jmshal/b14199f7402c8f3a4568733d8bed0f25 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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