write json file, return promise
495224
function writeJSON(filename, obj) {

    return new Promise(function (resolve, reject) {

      if (!Object.is(obj)) resolve(new Error('writeJSON requires the second argument to be an object'));

      _fs2['default'].writeFile(filename, JSON.stringify(obj, null, 2) + '\n', function (err) {
        if (err) reject(err);
        resolve(obj);
      });
    });
  }
262600
def _write_json(file, contents):
    """"""
    with open(file, 'w') as f:
        return json.dump(contents, f, indent=2, sort_keys=True)
1174298
function copyFile (src, dest) {
  return new Promise((resolve, reject) => {
    const read = fs.createReadStream(src);
    read.on('error', reject);
    const write = fs.createWriteStream(dest);
    write.on('error', reject);
    write.on('finish', resolve);
    read.pipe(write);
  })
}
384363
function writeStreamToFile(fileMeta, stream) {
  var deferred = q.defer();
  stream.on('end', function() {
    deferred.resolve(fileMeta);
  });
  stream.on('error', function(error) {
    deferred.reject(error);
  });
  var filename = imageDir + '/' + fileMeta.uid;
  stream.pipe(fs.createWriteStream(filename));
  return deferred.promise;
}
800155
function writeFile(namespace, fileName, fileLocation) {
  if (!gfsPromise) {
    return;
  }
  return gfsPromise.then(function(gfs) {
    var deferred = q.defer();
    var options = {
      filename: fileName
    };
    if (namespace) {
      options.root = namespace;
    }
    var writeStream = gfs.createWriteStream(options);
    writeStream.on('error', function(err) {
      console.log('An error occurred!', err);
      deferred.reject(err);
    });
    writeStream.on('close', function(file) {
      deferred.resolve(file);
    });
    fs.createReadStream(fileLocation).pipe(writeStream);
    return deferred.promise;
  });
}
851332
function writeState (state, localfile, cb) {
    // Write to global file
    try {
      var data = JSON.stringify( state.bins, null, 4 )
    } catch(e) {
      console.log('Problem parsing state into JSON for writing')
    }
    fs.writeFile( that.fglobal, data, 'utf8', function (err) {
      if (err) return cb(err)
      if (localfile) {
        // Write to local file
        try {
          var data = JSON.stringify( state.trackedfiles, null, 4 )
        } catch(e) {
          return cb( erf('Problem parsing tracked file state into JSON for writing') )
        }
        fs.writeFile( localfile, data, 'utf8', function (err) {
          if (err) return cb(err)
          return cb(null)
        }) // end WriteFile Local
      }
      else return cb(null) // no localfile
    }) // end WriteFile Global
  }
1320589
function write(description, options, callback) {
  var file = vfile(description)

  // Weird, right? Otherwise `fs` doesn’t accept it.
  if (!callback && typeof options === 'function') {
    callback = options
    options = undefined
  }

  if (!callback) {
    return new Promise(executor)
  }

  executor(resolve, callback)

  function resolve(result) {
    callback(null, result)
  }

  function executor(resolve, reject) {
    var fp

    try {
      fp = path.resolve(file.cwd, file.path)
    } catch (error) {
      return reject(error)
    }

    fs.writeFile(fp, file.contents || '', options, done)

    function done(error) {
      if (error) {
        reject(error)
      } else {
        resolve()
      }
    }
  }
}
1027284
def write_as_json(blob, dest, indent=0, sort_keys=True):
    
    opened_out = False
    if is_str_type(dest):
        out = codecs.open(dest, mode='w', encoding='utf-8')
        opened_out = True
    else:
        out = dest
    try:
        json.dump(blob, out, indent=indent, sort_keys=sort_keys)
        out.write('\n')
    finally:
        out.flush()
        if opened_out:
            out.close()
1072741
function(json, next) {
                fs.writeFile(out + "/" + path.basename(url).replace('.xml', '.json'), JSON.stringify(json), function (err) {
                    if (err) {
                        return next(err);
                    }
                    next(null, json);
                });
            }
638814
function writeFile(config, isJson, callback) {
  try {
    fs.writeFile('./.nplintrc', isJson ? JSON.stringify(config, null, 4) : yaml.safeDump(config), callback);
  } catch (e) {
    return callback(e);
  }
}
552295
function write (filename, content) {
  const json = JSON.stringify(content, (key, value) => value === undefined ? null : value)
  fs.writeFileSync(filename, json)
  return json
}
558951
function writeFile(fs, p, content, method, cb) {
    fs.metadata(p)
    .then(function(metadata) {
        if (metadata.is_dir) {
            throw fs.error('EISDIR');
        }
    }, function(e) {
        if (e.code === 'ENOENT') {
            var parent = path.dirname(p);
            return this.mkdir(parent);
        } else {
            throw e;
        }
    })
    .then(function() {
        return this._promise(method, p, content);
    })
    .done(cb, cb);
}
1032146
function write(drizzleData) {
  return Promise.all([
    writePages(drizzleData),
    writeCollections(drizzleData)
  ]).then(
    () => drizzleData,
    error => DrizzleError.error(error, drizzleData.options)
  );
}
130532
function writeFile(input, output, type) {
    var json    = readFile(input),
        content = getContent(json, type);

    fs.writeFile(output, content, function (err) {
        if (err) {
            throw err;
        }

        console.log('The file "' + output + '" was written successfully!');
    });
}
605833
function readJSON(path) {
  return new Promise(function ($return, $error) {
    var file, parsed;
    return Promise.resolve(read(path)).then(function ($await_1) {
      try {
        file = $await_1;
        parsed = JSON.parse(file);
        return $return(parsed);
      } catch ($boundEx) {
        return $error($boundEx);
      }
    }.bind(this), $error);
  }.bind(this));
}
1256888
function writeYamlFile(file, data) {
  return new Promise((resolve, reject) => {
    writeFile(file, toYaml(data))
      .then(resolve)
      .catch(reject);
  });
}
305279
function writeFile(filename, content) {
  fs.writeFileSync(filename, JSON.stringify(content, null, 2));
}