# libbase64

> Encode and decode base64 encoded strings

Latest version **1.3.0** (published 2024-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install libbase64
pnpm add libbase64
yarn add libbase64
bun add libbase64
```

## Health

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

Positive: no vulnerabilities; has provenance.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2024-02-23 |
| First published | 2014-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 10 |
| Author | Andris Reinman |
| Maintainers | andris |
| Keywords | base64, mime |

## Links

- npm: https://www.npmjs.com/package/libbase64
- Repository: https://github.com/nodemailer/libbase64
- Issues: https://github.com/nodemailer/libbase64/issues
- npm.io page: https://npm.io/package/libbase64

## 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.3.0 (latest) — 2024-02-23
- 1.2.1 — 2019-08-07
- 1.2.0 — 2019-08-06
- 1.1.0 — 2019-07-28
- 1.0.3 — 2018-07-24
- 1.0.2 — 2017-12-15
- 1.0.1 — 2017-11-26
- 1.0.0 — 2017-11-23
- 0.2.0 — 2017-06-06
- 0.1.0 — 2014-06-18

## README

# libbase64

Encode and decode base64 strings.

## Usage

Install with npm

    npm install libbase64

Require in your script

```javascript
const libbase64 = require('libbase64');
```

### Encode values

Encode Buffer objects or unicode strings with

    libbase64.encode(val) → String

Where

-   **val** is a Buffer or an unicode string

**Example**

```javascript
libbase64.encode('jõgeva');
// asO1Z2V2YQ==
```

### Wrap encoded values

To enforce soft line breaks on lines longer than selected amount of characters, use `wrap`

    libbase64.wrap(str[, lineLength]) → String

Where

-   **str** is a base64 encoded string
-   **lineLength** (defaults to 76) is the maximum allowed line length

**Example**

```javascript
libbase64.wrap('asO1Z2V2asO1Z2V2asO1Z2V2YQ==', 10);
// asO1Z2V2as\r\n
// O1Z2V2asO1\r\n
// Z2V2YQ==
```

### Transform Streams

`libbase64` makes it possible to encode and decode streams with `libbase64.Encoder` and `libbase64.Decoder` constructors.

### Encoder Stream

Create new Encoder Stream with

    const encoder = new libbase64.Encoder([options])

Where

-   **options** is the optional stream options object
-   **options.lineLength** (Number) if you want to use any other line length than the default 76
    characters (or set to `false` to turn the soft wrapping off completely)
-   **options.skipStartBytes** (Number) Optional. How many bytes to skip from output (default to 0)
-   **options.limitOutbutBytes** (Number) Optional. How many bytes to return (defaults to all bytes)
-   **options.startPadding** (String) Optional. Fills first line with provided padding string. Usually goes together with skipStartBytes to get line folding correct.

**Example**

The following example script reads in a file, encodes it to base64 and saves the output to a file.

```javascript
const libbase64 = require('libbase64');
const fs = require('fs');
const source = fs.createReadStream('source.txt');
const encoded = fs.createReadStream('encoded.txt');
const encoder = new libbase64.Encoder();

source.pipe(encoder).pipe(encoded);
```

### Decoder Stream

Create new Decoder Stream with

    const decoder = new libbase64.Decoder([options])

Where

-   **options** is the optional stream options object

**Example**

The following example script reads in a file in base64 encoding, decodes it and saves the output to a file.

```javascript
const libbase64 = require('libbase64');
const fs = require('fs');
const encoded = fs.createReadStream('encoded.txt');
const dest = fs.createReadStream('dest.txt');
const decoder = new libbase64.Decoder();

encoded.pipe(decoder).pipe(dest);
```

## License

**MIT**

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