Skip to content

A tiny npm module for saving Base64 encoded images that are part of data URLs to your file system.

License

Notifications You must be signed in to change notification settings

HarryStevens/ba64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ba64

Build Status Coverage Status

A tiny npm module for saving Base64 encoded images that are part of data URLs to your file system. This is useful for saving images that have been uploaded to the browser via FileReader.readAsDataUrl().

npm i ba64 -S
var ba64 = require("ba64"),
  data_url = "data:image/jpeg;base64,[Base64 encoded image goes here]";

// Save the image synchronously.
ba64.writeImageSync("myimage", data_url); // Saves myimage.jpeg.

// Or save the image asynchronously.
ba64.writeImage("myimage", data_url, function(err){
  if (err) throw err;

  console.log("Image saved successfully");

  // do stuff
});

# ba64.writeImage(path/to/file_name, data_url, callback)

Asynchronously saves the Base64 encoded image to the file system. file_name should not include the file extension; ba64 will do that for you.

# ba64.writeImageSync(path/to/file_name, data_url)

Synchronously saves the Base64 encoded image to the file system. file_name should not include the file extension; ba64 will do that for you.

Helper functions

# ba64.getExt(data_url)

Returns the file extension of the Base64 encoded image.

# ba64.getBa64Img(data_url)

Returns the Base64 encoded image without the data: scheme prefix.

About

A tiny npm module for saving Base64 encoded images that are part of data URLs to your file system.

Resources

License

Stars

Watchers

Forks

Packages

No packages published