strong-data-uri

Parser for data: URIs

strong-data-uri

strong-data-uri is implements a parser for retrieving data encoded in data: URIs specified by RFC2397, as well as an encoder for those URIs.

var dataUri = require('strong-data-uri');
var uri = 'data:text/plain;base64,aGVsbG8gd29ybGQ=';
 
var buffer = dataUri.decode(uri);
console.log(buffer);
// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64> 
console.log(buffer.toString('ascii'));
// Hello world 
 
uri = dataUri.encode('foo');
console.log(uri);
// data:application/octet-stream;base64,Zm9v 
uri = dataUri.encode(new Buffer('foo', 'utf8'), 'text/plain');
console.log(uri);
// data:text/plain;base64,Zm9v 

The module can parse both base64-encoded and url-encoded URLs at the moment.

Things that would be nice to have too:

  • Parse mediaType information and extract charset (encoding) value. This is needed to convert the returned Buffer into a string in cases where the application has to support arbitrary encodings.