JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2949
  • Score
    100M100P100Q117634F
  • License ISC

load conver and save files and images to base64 in js

Package Exports

  • js-base64-file

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js-base64-file) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Base64 File loading, converting and saving for node.js

This is an ideal way to load or convert local files to base64 either for use as a string or to save on disk.

method params description
<<<<<<< HEAD
load path,fileName,callback loads a local file and converts it to base64 if needed. *** note : path should always end with a / ***
loadSync path,fileName same as load, but it returns the base64 string instead of passing it to a callback. This could be slow on really large files.
save data,path,fileName,callback saves the data to the specified path and filename
callback params description
load err, base64Data gives you the base64 encoded file data
save err will pass any errors back

======= |load |path,fileName|loads a local file and converts it to base64 if needed. note : path should always end with a slash | |save |data,path,fileName,cb|saves the data to the specified path and filename|

643bc87a161affa912af2d7039f93da889193f4b

Examples

loading and converting an image for use in the browser as a data URI

    const Base64File=require('Base64File.js');
    const image=new Base64File;

    const file='test.png';

    //path should alwas end in a /
    const path=`${__dirname}/`;

    //this will load and convert if needed
    const data=image.loadSync(path,file);
    console.log('you could send this image via ws or http to the browser now : \n',data);

saving the above converted image for later use.

    image.save(data,path,`copy-b64-${file}`);

It's that simple! And it will work with any file type!