lib/utils.js
function write(filePath, data, mode, callback) {
  async.series([
    cb => mkdir(path.dirname(filePath), cb),
    (cb) => {
      if (mode === WriteMode.UTF8) {
        fs.writeFile(filePath, data, 'utf8', (error) => {
          if (error) {
            console.error(`${filePath}: Could not write the file`);
          }

          async.nextTick(cb, error);
        });
      } else if (mode === WriteMode.STREAM) {
        try {
          data.pipe(fs.createWriteStream(filePath));
          async.nextTick(cb, null);
        } catch (error) {
          console.error(`${filePath}: Could not create the write stream`);
          async.nextTick(cb, error);
        }
      }
    },
  ], error => async.nextTick(callback, error));
}
function write(filePath, data, mode, callback) {
  async.series([
    cb => mkdir(path.dirname(filePath), cb),
    (cb) => {
      if (mode === WriteMode.UTF8) {
        fs.writeFile(filePath, data, 'utf8', (error) => {
          if (error) {
            console.error(`${filePath}: Could not write the file`);
          }

          async.nextTick(cb, error);
        });
      } else if (mode === WriteMode.STREAM) {
        try {
          data.pipe(fs.createWriteStream(filePath));
          async.nextTick(cb, null);
        } catch (error) {
          console.error(`${filePath}: Could not create the write stream`);
          async.nextTick(cb, error);
        }
      }
    },
  ], error => async.nextTick(callback, error));
}
function write ( filePath , data , mode , callback ) { async . series ( [ cb => mkdir ( path . dirname ( filePath ) , cb ) , ( cb ) => { if ( mode === WriteMode . UTF8 ) { fs . writeFile ( filePath , data , 'utf8' , ( error ) => { if ( error ) { console . error ( ` ${ filePath } ` ) ; } async . nextTick ( cb , error ) ; } ) ; } else if ( mode === WriteMode . STREAM ) { try { data . pipe ( fs . createWriteStream ( filePath ) ) ; async . nextTick ( cb , null ) ; } catch ( error ) { console . error ( ` ${ filePath } ` ) ; async . nextTick ( cb , error ) ; } } } , ] , error => async . nextTick ( callback , error ) ) ; }
Write a file.
Write a file .