1.4.1 • Published 7 years ago

base64-file-encoder v1.4.1

Weekly downloads
12
License
MIT
Repository
github
Last release
7 years ago

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.

1.4.1

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago