datauri-stream
v1.0.3
Published
Lightweight data -> data URI transform stream
Downloads
39
Readme
datauri-stream
Lightweight data
─► data URI
transform stream.
examples
Use with the file system:
var DataUri = require('datauri-stream')
var fs = require('fs')
fs.createReadStream('./picture.jpg')
.pipe(DataUri())
.pipe(process.stdout)
// 'data:image/jpg;base64,iVBORw0KGg...'
Use with http requests:
var DataUri = require('datauri-stream')
var http = require('http')
http.get('http://josephdykstra.com/logo.png', function(res) {
res.pipe(DataUri())
.pipe(process.stdout)
// 'data:image/png;base64,Vs8uZ29vZG...'
})
Use on the browser with browserify:
var DataUri = require('datauri-stream')
var hyperquest = require('hyperquest')
var concat = require('concat-stream')
hyperquest('https://www.npmjs.com/static/images/npm-logo.svg')
.pipe(DataUri({ mime: 'image/svg' }))
.pipe(concat(function (dataUri) {
var img = document.createElement('img')
img.src = dataUri
document.body.appendChild(img)
}))
api
var DataUriStream = require('datauri-stream')
var ts = DataUriStream([opts])
opts.mime
An optional override for the mime type.
The mime type will be automatically detected otherwise, using the file-type module. It supports many file types.
If the source is not a file, then you'll want to supply the mime type.
ts
A standard Transform Stream. Pipe to and from it.