Last active
April 27, 2024 04:12
-
-
Save jmshal/b14199f7402c8f3a4568733d8bed0f25 to your computer and use it in GitHub Desktop.
Node.js ponyfill for atob and btoa encoding functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function atob(a) { | |
return new Buffer(a, 'base64').toString('binary'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function btoa(b) { | |
return new Buffer(b).toString('base64'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
atob: require('./atob'), | |
btoa: require('./btoa'), | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "atob-btoa.js", | |
"version": "1.0.0", | |
"description": "Node.js ponyfill for atob and btoa encoding functions" | |
} |
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
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
"