Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const fs = require('fs');
  2. const regex = /(\.|\/)(gif|jpe?g|png|txt)$/i;
  3. const dir = './';
  4.  
  5. fs.readdir(dir, function(err, files) {
  6. files.forEach(function(file) {
  7. // Skip current file
  8. if (file === __filename.slice(__dirname.length + 1)) return;
  9.  
  10. fs.readFile(`${dir}${file}`, {encoding: 'base64'}, function(err, str) {
  11. return err if err;
  12.  
  13. const ext = regex.exec(file)[2];
  14. console.log('################################################################################');
  15. console.log(file);
  16. console.log(`data:image/${ext};base64,${str}`);
  17. console.log('################################################################################');
  18. });
  19. });
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement