@stdlib/string-base-base64-to-uint8array
v0.1.1
Published
Convert a Base64-encoded string to a Uint8Array.
Readme
base64ToUint8Array
Convert a Base64-encoded string to a Uint8Array.
Installation
npm install @stdlib/string-base-base64-to-uint8arrayUsage
var base64ToUint8Array = require( '@stdlib/string-base-base64-to-uint8array' );base64ToUint8Array( str )
Converts a base64-encoded string to a Uint8Array.
var string2buffer = require( '@stdlib/buffer-from-string' );
var str = string2buffer( 'Hello World!' ).toString( 'base64' );
// returns 'SGVsbG8gV29ybGQh'
var out = base64ToUint8Array( str );
// returns <Uint8Array>[ 72, 101, ... ]Notes
- The function returns
nullwhen provided a string containing non-ASCII characters.
Examples
var string2buffer = require( '@stdlib/buffer-from-string' );
var base64ToUint8Array = require( '@stdlib/string-base-base64-to-uint8array' );
var buf = string2buffer( 'Hello World!' ).toString( 'base64' );
// returns 'SGVsbG8gV29ybGQh'
var arr = base64ToUint8Array( buf );
// returns <Uint8Array>
buf = string2buffer( 'HELLO WORLD!' ).toString( 'base64' );
// returns 'SEVMTE8gV09STEQh'
arr = base64ToUint8Array( buf );
// returns <Uint8Array>
buf = string2buffer( 'To be, or not to be: that is the question.' ).toString( 'base64' );
// returns 'VG8gYmUsIG9yIG5vdCB0byBiZTogdGhhdCBpcyB0aGUgcXVlc3Rpb24u'
arr = base64ToUint8Array( buf );
// returns <Uint8Array>Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
