Code Monkey home page Code Monkey logo

libbase64's Introduction

libbase64

Encode and decode base64 strings.

Usage

Install with npm

npm install libbase64

Require in your script

var 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

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

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

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

Where

  • options is the optional stream options object with an additional option lineLength 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)

Example

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

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

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

Decoder Stream

Create new Decoder Stream with

var 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.

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

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

License

MIT

libbase64's People

Contributors

andris9 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.