function file(options, callback) {
  var
    args = _parseArguments(options, callback),
    opts = args[0],
    cb = args[1];

  opts.postfix = (_isUndefined(opts.postfix)) ? '.tmp' : opts.postfix;

  // gets a temporary filename
  tmpName(opts, function _tmpNameCreated(err, name) {
    if (err) return cb(err);

    // create and open the file
    fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
      if (err) return cb(err);

      if (opts.discardDescriptor) {
        return fs.close(fd, function _discardCallback(err) {
          if (err) {
            // Low probability, and the file exists, so this could be
            // ignored.  If it isn't we certainly need to unlink the
            // file, and if that fails too its error is more
            // important.
            try {
              fs.unlinkSync(name);
            } catch (e) {
              if (!isENOENT(e)) {
                err = e;
              }
            }
            return cb(err);
          }
          cb(null, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts));
        });
      }
      if (opts.detachDescriptor) {
        return cb(null, name, fd, _prepareTmpFileRemoveCallback(name, -1, opts));
      }
      cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
    });
  });
}
/**
 * Creates and opens a temporary file.
 *
 * @param {(Options|fileCallback)} options the config options or the callback function
 * @param {?fileCallback} callback
 */
Creates and opens a temporary file.
@param {(Options|fileCallback)} options the config options or the callback function
@param {?fileCallback} callback
Creates and opens a temporary file . @param { ( Options|fileCallback ) } options the config options or the callback function @param { ?fileCallback } callback
function file(options, callback) {
  var
    args = _parseArguments(options, callback),
    opts = args[0],
    cb = args[1];
  opts.postfix = (_isUndefined(opts.postfix)) ? '.tmp' : opts.postfix;
  tmpName(opts, function _tmpNameCreated(err, name) {
    if (err) return cb(err);
    fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
      if (err) return cb(err);
      if (opts.discardDescriptor) {
        return fs.close(fd, function _discardCallback(err) {
          if (err) {
            try {
              fs.unlinkSync(name);
            } catch (e) {
              if (!isENOENT(e)) {
                err = e;
              }
            }
            return cb(err);
          }
          cb(null, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts));
        });
      }
      if (opts.detachDescriptor) {
        return cb(null, name, fd, _prepareTmpFileRemoveCallback(name, -1, opts));
      }
      cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
    });
  });
}
function file ( options , callback ) { var args = _parseArguments ( options , callback ) , opts = args [ 0 ] , cb = args [ 1 ] ; opts . postfix = ( _isUndefined ( opts . postfix ) ) ? '.tmp' : opts . postfix ; tmpName ( opts , function _tmpNameCreated ( err , name ) { if ( err ) return cb ( err ) ; fs . open ( name , CREATE_FLAGS , opts . mode || FILE_MODE , function _fileCreated ( err , fd ) { if ( err ) return cb ( err ) ; if ( opts . discardDescriptor ) { return fs . close ( fd , function _discardCallback ( err ) { if ( err ) { try { fs . unlinkSync ( name ) ; } catch ( e ) { if ( ! isENOENT ( e ) ) { err = e ; } } return cb ( err ) ; } cb ( null , name , undefined , _prepareTmpFileRemoveCallback ( name , - 1 , opts ) ) ; } ) ; } if ( opts . detachDescriptor ) { return cb ( null , name , fd , _prepareTmpFileRemoveCallback ( name , - 1 , opts ) ) ; } cb ( null , name , fd , _prepareTmpFileRemoveCallback ( name , fd , opts ) ) ; } ) ; } ) ; }
Creates and opens a temporary file.
Creates and opens a temporary file .
// gets a temporary filename // create and open the file // Low probability, and the file exists, so this could be // ignored.  If it isn't we certainly need to unlink the // file, and if that fails too its error is more // important.