base64-file-encoder

1.4.1 • Public • Published

npm Hits

base64-file-encoder

A Node.js module to base64 encode/decode a file and save it to disk

NPM

Installation

Install with npm:

$ npm install base64-file-encoder --save

Example

const b64File = require('base64-file-encoder');
 
 
// base64 encodes the content of foo.txt and outputs it to bar.txt
b64File.encode('foo.txt', 'bar.txt')
  .then(function(){
    // if foo.txt content was 'foo', bar.txt content will be 'Zm9v'
    console.log('file was encoded');
  })
  .catch(function(error){
    console.log(error);
  });
 
 
// base64 encodes the content of foo.txt and outputs it to the same
// file (i.e. overwrites it)
b64File.encode('foo.txt')
  .then(function(){
    console.log('file was encoded and overwritten');
  })
  .catch(function(error){
    console.log(error);
  });
 
 
// base64 decodes the content of bar.txt and outputs it to foo.txt
b64File.decode('bar.txt', 'foo.txt')
  .then(function(){
    // if bar.txt content was 'Zm9v', foo.txt content will be 'foo'
    console.log('file was decoded');
  })
  .catch(function(error){
    console.log(error);
  });
 
 
// base64 decodes the content of bar.txt and outputs it to the same
// file (i.e. overwrites it)
b64File.decode('bar.txt')
  .then(function(){
    console.log('file was decoded and overwritten');
  })
  .catch(function(error){
    console.log(error);
  });

API

encode(inputFilePath, [outputFilePath])

Base64 encodes the contents of a file and outputs it to another file (outputFilePath) or to the same file (if outputPath is not provided).
This function returns a promise.

decode(inputFilePath, [outputFilePath])

Decodes the contents of a base64 encoded file and outputs it to another file (outputFilePath) or to the same file (if outputPath is not provided).
This function returns a promise.

License

MIT. See LICENSE.md for details.

Package Sidebar

Install

npm i base64-file-encoder

Weekly Downloads

6

Version

1.4.1

License

MIT

Last publish

Collaborators

  • andersonmamede