1.0.0 • Published 7 years ago

base64-stream v1.0.0

Weekly downloads
106,725
License
MIT
Repository
github
Last release
7 years ago

Introduction

While Node.js has built-in support for Base64 data, it does not come with the ability to encode / decode data in a stream.

This library contains a streaming Base64 encoder and a streaming Base64 decoder for use with Node.js. These classes are written using the Node.js stream interfaces and are well covered with unit tests.

Usage

Installation

To install base64-stream

npm install base64-stream

Examples

This example encodes an image and pipes it to stdout.

var http = require('http');
var {Base64Encode} = require('base64-stream');

var img = 'http://farm3.staticflickr.com/2433/3973241798_86ddfa642b_o.jpg';
http.get(img, function(res) {
    if (res.statusCode === 200)
        res.pipe(new Base64Encode()).pipe(process.stdout);
});

This example takes in Base64 encoded data on stdin, decodes it, an pipes it to stdout.

var {Base64Encode} = require('base64-stream');
process.stdin.pipe(new Base64Encode()).pipe(process.stdout);

options:

Base64Encode can take an optional object {lineLength: number, prefix: string}
The prefix is useful for prepending for example data:image/png;base64, to make a base64 URL.
This example proxies an image url, and send the base64 string in response.

app.get('/i/*', function(req, res){ // using express for example
	fetch(req.params[0]) // using node-fetch
	.then(r=>r.body.pipe(new Base64Encode({prefix:`data:${r.headers.get('content-type')};base64,`})).pipe(res))
	.catch(console.error);
});

Requirements

This module currently requires Node 6.0.0 or higher.

Testing

To run the unit tests

npm test

License

MIT

md-common-servicesenres-node-pluginenres-pluginaiosdk-js@everything-registry/sub-chunk-1216simply-benefits-apiweb_auto_codeceptjsweetiquetaswicked-coolkitsubmit-checker-h3sv_node_sharetextpressvmext@dkaframework/document@creately/image-to-png@blinkz/rets-clientiterm2-imagejsperf-img-svcstring-helper-sampletilelive-csvintransfer-sh@appium/support@anaidenko/rets-client@adonisinoda/gerar-boletos@backstage/backend-common@backstage/backend-defaults@ballerine/workflows-service@bambulabs/finedine-printer@bidipass/sdk@datumnetwork/datum-sdk@dfriedenberger/thing-libwavpackvip-cb-customer-configs-migration@grupoessent/gerar-boletos@grpc-web/middleware@humanmade/cli@esvinson/rets-client@infrascan/cytosnap@natanbarbosa2/boleto.ts@nnnx/websocket@fanai/firestore-utils@megres/gerar-boletos@joplinapp/lib@joplin/lib@ia-cloud/node-red-contrib-ia-cloud-fds@rechat/rets-client@opendesign/svg-exporter@notlekmelo/gerar-boletos@opra/http@slosarek/rets-client@soyjak/utils@ronoaldo/codebox@sikka/silk@sikka/hajar@shotputter/api@sitetheory/rets-clientopal-node-emailobject-detectionparking-spot-datapavemint-datascreenshot-streamrome-minsapims3-proxy-indexs3-proxy-middlewares3-proxyremovdnode-s3-proxynode-rets-clientndx-file-uploadnfw-corenode-webospino-eventhubpostgres-blob-storepoodle-servicerandom-gif-splitrets-clientsfdysfdx-mohanc-pluginsshashinsimon-hellosimayasnapshot-streamgrunt-regressgraphql-bob-serverimap-promiseimap-promise-forkedimap-riyohotplatehappo-e2einovar-boletos-pdfinstaller-makerlilypad-rivetmagic-erasemanraymapperidea-climath-ast@xilinota/lib@thinkeloquent/phantomjs-xhr@thinkeloquent/screenshot-stream
1.0.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

10 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.1

12 years ago