Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const regex = /(\.|\/)(gif|jpe?g|png|txt)$/i;
- const dir = './';
- fs.readdir(dir, function(err, files) {
- files.forEach(function(file) {
- // Skip current file
- if (file === __filename.slice(__dirname.length + 1)) return;
- fs.readFile(`${dir}${file}`, {encoding: 'base64'}, function(err, str) {
- return err if err;
- const ext = regex.exec(file)[2];
- console.log('################################################################################');
- console.log(file);
- console.log(`data:image/${ext};base64,${str}`);
- console.log('################################################################################');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement