项目作者: AndersonMamede

项目描述 :
base64 encode/decode a file and save it to disk
高级语言: JavaScript
项目地址: git://github.com/AndersonMamede/base64-file-encoder.git
创建时间: 2017-08-28T13:13:21Z
项目社区:https://github.com/AndersonMamede/base64-file-encoder

开源协议:MIT License

下载


npm

base64-file-encoder

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

NPM

Installation

Install with npm:

  1. $ npm install base64-file-encoder --save

Example

  1. const b64File = require('base64-file-encoder');
  2. // base64 encodes the content of foo.txt and outputs it to bar.txt
  3. b64File.encode('foo.txt', 'bar.txt')
  4. .then(function(){
  5. // if foo.txt content was 'foo', bar.txt content will be 'Zm9v'
  6. console.log('file was encoded');
  7. })
  8. .catch(function(error){
  9. console.log(error);
  10. });
  11. // base64 encodes the content of foo.txt and outputs it to the same
  12. // file (i.e. overwrites it)
  13. b64File.encode('foo.txt')
  14. .then(function(){
  15. console.log('file was encoded and overwritten');
  16. })
  17. .catch(function(error){
  18. console.log(error);
  19. });
  20. // base64 decodes the content of bar.txt and outputs it to foo.txt
  21. b64File.decode('bar.txt', 'foo.txt')
  22. .then(function(){
  23. // if bar.txt content was 'Zm9v', foo.txt content will be 'foo'
  24. console.log('file was decoded');
  25. })
  26. .catch(function(error){
  27. console.log(error);
  28. });
  29. // base64 decodes the content of bar.txt and outputs it to the same
  30. // file (i.e. overwrites it)
  31. b64File.decode('bar.txt')
  32. .then(function(){
  33. console.log('file was decoded and overwritten');
  34. })
  35. .catch(function(error){
  36. console.log(error);
  37. });

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.