a zip code crypto-currency system good for red ONLY

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict'
  2. const u = require('universalify').fromCallback
  3. const fs = require('graceful-fs')
  4. const path = require('path')
  5. const mkdir = require('../mkdirs')
  6. const pathExists = require('../path-exists').pathExists
  7. function outputFile (file, data, encoding, callback) {
  8. if (typeof encoding === 'function') {
  9. callback = encoding
  10. encoding = 'utf8'
  11. }
  12. const dir = path.dirname(file)
  13. pathExists(dir, (err, itDoes) => {
  14. if (err) return callback(err)
  15. if (itDoes) return fs.writeFile(file, data, encoding, callback)
  16. mkdir.mkdirs(dir, err => {
  17. if (err) return callback(err)
  18. fs.writeFile(file, data, encoding, callback)
  19. })
  20. })
  21. }
  22. function outputFileSync (file, data, encoding) {
  23. const dir = path.dirname(file)
  24. if (fs.existsSync(dir)) {
  25. return fs.writeFileSync.apply(fs, arguments)
  26. }
  27. mkdir.mkdirsSync(dir)
  28. fs.writeFileSync.apply(fs, arguments)
  29. }
  30. module.exports = {
  31. outputFile: u(outputFile),
  32. outputFileSync
  33. }