# base64-stream

> Contains new Node.js v0.10 style stream classes for encoding / decoding Base64 data

Latest version **1.0.0** (published 2018-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install base64-stream
pnpm add base64-stream
yarn add base64-stream
bun add base64-stream
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-10-14 |
| First published | 2013-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/base64-stream) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 118 |
| Author | Ross Johnson |
| Maintainers | rossj |
| Keywords | Base64, stream, streaming, piping, node, node.js, encode, decode |

## Links

- npm: https://www.npmjs.com/package/base64-stream
- Repository: https://github.com/mazira/base64-stream
- Homepage: https://github.com/mazira/base64-stream#readme
- Issues: https://github.com/mazira/base64-stream/issues
- npm.io page: https://npm.io/package/base64-stream

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-10-14
- 0.1.5 — 2018-10-14
- 0.1.4 — 2018-10-12
- 0.1.3 — 2015-10-09
- 0.1.2 — 2013-07-11
- 0.1.1 — 2013-07-09
- 0.1.0 — 2013-07-09
- 0.0.1 — 2013-07-09

## README

# 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](http://nodejs.org/api/stream.html) 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.

```javascript
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.
```javascript
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

---
_Source: https://npm.io/package/base64-stream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
