1.0.0 • Published 5 years ago

base64-stream v1.0.0

Weekly downloads
106,725
License
MIT
Repository
github
Last release
5 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-apimapperidea-clijsperf-img-svcndx-file-uploadnfw-coremagic-erasemanraynode-webosmath-ast@soyjak/utils@thinkeloquent/screenshot-stream@torpadev/orpa-node-email@thinkeloquent/phantomjs-xhr@slosarek/rets-client@telligro/opal-node-emailairfile@xilinota/libaltis-cliaa-imap-promise-forkaesh@anaidenko/rets-clientbase64-string-s3auto-pdf-creator@backstage/backend-commonblittercirruswaveclouddrivecli-webos@datumnetwork/datum-sdk@dfriedenberger/thing-lib@bidipass/sdk@blinkz/rets-clientbookingdojo@ballerine/workflows-serviceboco-encryptionboleto-montadorboletos.tsnode-s3-proxyobject-detectionnode-rets-clientrandom-gif-splitopal-node-emailpostgres-blob-storepoodle-serviceparking-spot-datapavemint-datapino-eventhubs3-proxys3-proxy-indexs3-proxy-middlewareremovdscreenshot-streamvmextvip-cb-customer-configs-migrationtransfer-shtextpresswavpackweetiquetasweb_auto_codeceptjswicked-coolkittilelive-csvinsfdysfdx-mohanc-pluginsshashinsnapshot-streamsv_node_sharesubmit-checker-h3string-helper-samplerets-clientrome-minsapimsimon-hellosimayacodeboxcodebox-lite@creately/image-to-pngcodestates-assignment-managercloud-compute-cannoncloud-compute-cannon-clientemailclient@ia-cloud/node-red-contrib-ia-cloud-fdscreate-billcreate-bill-2crypto-busboycytosnapappium-support@adonisinoda/gerar-boletosares-ideares-ecosystem-ideares-webos-sdkarmor-support@appium/support@fanai/firestore-utils@grpc-web/middleware@humanmade/cli
1.0.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

8 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.1

11 years ago