Write the string data to file.
Asynchronous mode
@param {string} filename
@param {string} data
@returns {promise}
546807
function writeFile(filename, data) {
    return new Promise(function (fulfill, reject) {
        fs.writeFile(filename, data, function (err, res) {
            return err ? reject(err) : fulfill(res);
        });
    });
}
1143593
function writeFileSync(cvs, data) {
    if (typeof data.path !== 'string') {
      throw new TypeError('Invalid path type: ' + typeof data.path);
    }

    var buff = cvs.toBuffer();
    var fd = fs.openSync(data.path, 'w', WRITE_MODE);

    try {
      fs.writeSync(fd, buff, 0, buff.length, 0);
    } catch (error) {
      fs.closeSync(fd);
    }
  }
531603
function writeSync(description, options) {
  var file = vfile(description)
  fs.writeFileSync(
    path.resolve(file.cwd, file.path),
    file.contents || '',
    options
  )
}
635353
def write(fname, data):
		
		try:
			with open(fname, 'w') as f:
				json.dump(data, f)

		except IOError:
			raise Exception('Could not open {0!s} for writing'.format((fname)))
405750
function writeFile(file, css) {
  return new Promise((resolve, reject) => {
    fs.writeFile(file, css, err => {
      if (err) {
        return reject(err);
      }
      resolve();
    })
  });
}
490266
function _writeFile(i_sFilename, i_oFile, i_oCallback) {
    var l_sFilename = i_sFilename,
        l_oBuffer = new Buffer(i_oFile.fileData); // filedata is Uint8Array
    fs.writeFile(l_sFilename, l_oBuffer, function(err) {
        if (err) {
            console.log("Error writting file ", err);
            l_sFilename = null;
        }
        i_oCallback(l_sFilename);
    });
}
851468
function saveData(data) {
    console.log('saving data', data);
    if (options.cacheKeys) {
      cachedKeys = Object.keys(data);
    }
    if (file === false) {
      return Promise.resolve();
    } else {
      return writeFile(file, JSON.stringify(data, null, 2));
    }
  }
534694
async function(filename, compress, result) {
  const content = JSON.stringify(result);

  const data = compress ? await gzip(content) : content;
  return await writeFile(filename + (compress ? ".gz" : ""), data);
}
950046
async function writeStream (filename, contents) {
  await new Promise((resolve, reject) => {
    contents.pipe(fs.createWriteStream(filename))
      .on('finish', function () {
        resolve(filename)
      })
      .on('error', /* istanbul ignore next */ function (err) {
        reject(err)
      })
  })
  return filename
}
15109
function(options, filename){	    
	    Joi.assert(filename, Joi.string())
	    return new Promise(function(resolve, reject){

	        try{	            

	            var writestream = fs.createWriteStream(filename);
	            request(options).pipe(writestream);

	            writestream.on('finish', function(err){                 
	                if(err){
	                    reject({
	                        "path" : filename,
	                        "status" : false,
	                        "error": err
	                    });
	                }else{
	                    resolve({
	                        "path" : filename,
	                        "status" : true
	                    });
	                }
	            });

	        }catch(e){
	            reject(e);
	        }
	    });
	}
422862
function(fileName, content) {
                return Promise()
                .then(function() {
                    var filePath = PathUtils.resolveInRoot(outputFolder, fileName);

                    return fs.exists(filePath);
                });
            }
1098694
function loadArff(fileName, callback) {
  ARFF.load(fileName, (error, data) => {
    if (error) {
      throw new Error(filename + error);
    }
    callback(data);
  });
  
  return 'THIS IS ASYNCHRONOUS';
}
552827
function (data) {
      var include = function (path, includeData) {
        var d = utils.shallowCopy({}, data);
        if (includeData) {
          d = utils.shallowCopy(d, includeData);
        }
        var p = includeFile(path, opts)(d);
        return p;
      };
      
      var error = null;
      
      var outputStreamOpts = utils.shallowCopy({}, opts.streamOptions);
      var outputStreamBufferOpts = utils.shallowCopy({}, opts.streamOptions);
      outputStreamBufferOpts.flush = function (cb) {
        cb(error);
      }
      
      var outputStream = new PassThrough(outputStreamOpts);
      var outputStreamBuffer = new PassThrough(outputStreamBufferOpts);
      
      // outputStream.write('');
      outputStream.pipe(outputStreamBuffer);
      
      var p = utils.wrapToPromise(fn, opts.context, Promise, data || {}, escape, include, rethrow, Promise, utils.wrapToPromise, outputStream, Stream);
      
      p.shouldUseBuffer = true;
      p.noBuffer = function () {
        p.outputBuffer = ""
        p.shouldUseBuffer = false;
      }
      p.useBuffer = function () {
        p.shouldUseBuffer = true;
      }
      
      
      // do not continue the script if it is not appropriate to resume writing data to the stream.
      // https://nodejs.org/api/stream.html#stream_event_drain
      p.shouldWaitFlush = false;
      Object.defineProperty(outputStream, 'shouldWaitFlush', {
        get: function () {
          return p.shouldWaitFlush
        },
        set: function (val) {
          p.shouldWaitFlush = val
          return true;
        }
      })
      p.waitFlush = function () {
        p.shouldWaitFlush = true;
      }
      p.noWaitFlush = function () {
        p.shouldWaitFlush = false;
      }
      
      
      p.outputBuffer = ""
      // since the stream got consumed immediatly, we need another stream to buffer it;
      p.outputStream = outputStreamBuffer;
      // a test only property
      p._outputStream = outputStream;
      // since we need to escape the text, and escape only works on string
      outputStream.setEncoding('utf8');
      
      // redirect data to the buffer
      outputStream.on('data', function (data) {
        if (!p.shouldUseBuffer) return;
        p.outputBuffer += data;
      })
      
      // resolve the promise after stream end, so we can get all data.
      outputStream.on('end', function (data) {
        p.defered.resolve(p.outputBuffer)
      })
      
      // hook after generator exit normally
      p.defered.onResolve = function (defered) {
        outputStream.end();
        // force it to flush all buffer since a pipe to fulfilled target prohibit
        // the stream from flushing the data
        // outputStream.uncork();
        
        // use read directly, since uncork sometimes fail to dunp the stream
        while (outputStream.read()) {}
      }
      
      // hook for situation the generator throws
      p.defered.onReject = function (defered, err) {
        // the promise should be reject before stream got end, 
        // or it will cause the stream to think it terminate normally, 
        // since there is not any error event before the end event and promise reject
        defered.reject(err)
        
        // emit only if the user decide to listen to stream's error event instead of promise reject
        // the stream.pipe bind a error listener to stream, so we need to count it
        if (outputStreamBuffer.listenerCount('error') > 1) {
          error = err;
        }
        outputStream.end();
        // force it to flush all buffer since a pipe to fulfilled target prohibit
        // the stream from flushing the data
        // outputStream.uncork();
        
        // use read directly, since uncork sometimes fail to dunp the stream
        while (outputStream.read()) {}
      }
      
      // terminate the stream, prevent further writing
      p.defered.onInterrupt = function (cb) {
        outputStream.end();
        cb();
      }
      
      setTimeout(function() {
        p.execute();
      }, 0)
      return p;
    }
89159
function __save(filename, content, json){
  json = json === true

  if (json) {
    fs.writeFileSync(filename, JSON.stringify(content))
  } else {
    fs.writeFileSync(filename, content)
  }
}
175045
function (data, callback) {
    if (typeof txDataQueue != "undefined" || txInProgress) {
      if (txDataQueue === undefined)
        txDataQueue = "";
      txDataQueue += data;
      return callback();
    } else {
      txDataQueue = data;
    }

    function writeChunk() {
      var chunk;
      var CHUNKSIZE = 20;
      if (txDataQueue.length <= CHUNKSIZE) {
        chunk = txDataQueue;
        txDataQueue = undefined;
      } else {
        chunk = txDataQueue.substr(0, CHUNKSIZE);
        txDataQueue = txDataQueue.substr(CHUNKSIZE);
      }
      txInProgress = true;
      console.log("BT> Sending " + JSON.stringify(chunk));
      try {
        winnus.write(chunk);
        setTimeout(function() {
          txInProgress = false;
          if (txDataQueue)
            writeChunk();
        }, 20);
      } catch (e) {
        console.log("BT> ERROR " + e);
        txDataQueue = undefined;
      }
    }
    writeChunk();
    return callback();
  }
74430
public static function write($fileName, $data, $mode = 'w')
    {
        if ($mode != 'w' && $mode != 'w+') {
            throw new \InvalidArgumentException('mode "'.$mode.'" is not valid');
        }
        if (!file_exists($fileName)) {
            if (!is_writable(dirname($fileName))) {
                throw new RuntimeException($fileName.' not writable');
            }
        } else {
            if (!is_writable($fileName)) {
                throw new RuntimeException($fileName.' not writable');
            }
        }

        $handler = fopen($fileName, $mode);
        fwrite($handler, (string) $data);
        fclose($handler);
    }
807526
function write (database) {
  var deferred = q.defer();

  // Write database to file under database name
  fs.writeFile(globalConfig.db.location + database + '.db.json', JSON.stringify(databases[database]), function (err) {
    if(err) return deferred.reject(err);

    deferred.resolve();
  });

  return deferred.promise;
}