lib/dirio.js
function _write(dest, source, callback) {
  var itemPath = path.join(dest, source.name);
  // switch according to type of the current root item
  switch(source.type) {
    case TYPE_FILE:
      if (source.data instanceof stream.Readable) {
        // stream data => pipe it to destination stream
        source.data.pipe(fs.createWriteStream(itemPath));
        source.data.on('end', callback);
        return;
      }
      // write data to the file as a string or a buffer
      return fs.writeFile(
        itemPath,
        (typeof source.data === 'undefined' || source.data === null) ? '' : source.data,
        callback
      );
    case TYPE_FOLDER:
      return fs.mkdir(itemPath, _folderWritten.bind(null, itemPath, source, callback));
    case TYPE_ALIAS:
      return fs.symlink(source.orig, itemPath, callback);
    default:
      // ignore unknown type
      return callback();
  }
}
function _write(dest, source, callback) {
  var itemPath = path.join(dest, source.name);
  // switch according to type of the current root item
  switch(source.type) {
    case TYPE_FILE:
      if (source.data instanceof stream.Readable) {
        // stream data => pipe it to destination stream
        source.data.pipe(fs.createWriteStream(itemPath));
        source.data.on('end', callback);
        return;
      }
      // write data to the file as a string or a buffer
      return fs.writeFile(
        itemPath,
        (typeof source.data === 'undefined' || source.data === null) ? '' : source.data,
        callback
      );
    case TYPE_FOLDER:
      return fs.mkdir(itemPath, _folderWritten.bind(null, itemPath, source, callback));
    case TYPE_ALIAS:
      return fs.symlink(source.orig, itemPath, callback);
    default:
      // ignore unknown type
      return callback();
  }
}
function _write ( dest , source , callback ) { var itemPath = path . join ( dest , source . name ) ; // switch according to type of the current root item switch ( source . type ) { case TYPE_FILE : if ( source . data instanceof stream . Readable ) { // stream data => pipe it to destination stream source . data . pipe ( fs . createWriteStream ( itemPath ) ) ; source . data . on ( 'end' , callback ) ; return ; } // write data to the file as a string or a buffer return fs . writeFile ( itemPath , ( typeof source . data === 'undefined' || source . data === null ) ? '' : source . data , callback ) ; case TYPE_FOLDER : return fs . mkdir ( itemPath , _folderWritten . bind ( null , itemPath , source , callback ) ) ; case TYPE_ALIAS : return fs . symlink ( source . orig , itemPath , callback ) ; default : // ignore unknown type return callback ( ) ; } }
Writes fs structure according to provided source object.
@param {String} dest - Path to destination location on file system.
@param {Object} source - Description of the structure to be created.
@param {Function} callback - Callback that expects only a possible
error.
Writes fs structure according to provided source object .