Put, possibly replace, file contents with (new) data
429243
def write(self, data):
        ''
        if not hasattr(data, 'read'):
            data = six.BytesIO(data)#StringIO(data)
        self.jfs.up(self.path, data)
1322733
def put content, destination, on_conflict=:overwrite

      if on_conflict != :overwrite && Content::Item.new( destination ).exists?
        case on_conflict
        when :skip then return
        when :prompt then
          input = Util.get_input "a file already exists at #{destination}\noverwrite? (y|n): "
          return unless input.downcase == "y"
        when :raise_error then
          raise "File already exists at #{destination}"
        end
      end

      Content.put content, destination
    end
922336
static function append_file($file_path_and_name, $file_content, $overwrite = false)
    {
        echo ("Appending the file: ".$file_path_and_name.PHP_EOL);
        if ($overwrite) {
            file_put_contents($file_path_and_name, $file_content);
        } else {
            file_put_contents($file_path_and_name, $file_content, FILE_APPEND);
        }
    }
947778
function overwriteFile(path, options) {
  let fileContent = null;
  let newData = null;

  try {
    fileContent = fs.readFileSync(path, 'utf8');
    newData = visit(JSON.parse(fileContent), options);
  } catch (e) {
    console.error('Failed to retrieve json object from file');
    throw e;
  }

  let indent;

  if (options && options.indentSize) {
    indent = options.indentSize;
  } else {
    indent = detectIndent(fileContent).indent || DEFAULT_INDENT_SIZE;
  }

  const newLine = detectNewline(fileContent) || '\n';
  let newFileContent = JSON.stringify(newData, null, indent);

  if (!(options && options.noFinalNewLine)) {
    // Append a new line at EOF
    newFileContent += '\n';
  }

  if (newLine !== '\n') {
    newFileContent = newFileContent.replace(/\n/g, newLine);
  }

  fs.writeFileSync(path, newFileContent, 'utf8');
  return newData;
}
542666
def update_contents(self, stream, seek=0, size=None, chunk_size=None,
                        progress_callback=None, **kwargs):
        
        self.checksum = None
        return self.storage(**kwargs).update(
            stream, seek=seek, size=size, chunk_size=chunk_size,
            progress_callback=progress_callback
        )
1053210
def put(self, filename, data):
        
        # Open the file for writing on the board and write chunks of data.
        self._pyboard.enter_raw_repl()
        self._pyboard.exec_("f = open('{0}', 'wb')".format(filename))
        size = len(data)
        # Loop through and write a buffer size chunk of data at a time.
        for i in range(0, size, BUFFER_SIZE):
            chunk_size = min(BUFFER_SIZE, size - i)
            chunk = repr(data[i : i + chunk_size])
            # Make sure to send explicit byte strings (handles python 2 compatibility).
            if not chunk.startswith("b"):
                chunk = "b" + chunk
            self._pyboard.exec_("f.write({0})".format(chunk))
        self._pyboard.exec_("f.close()")
        self._pyboard.exit_raw_repl()
334617
def add_data_file(data_files, target, source):
    """"""
    for t, f in data_files:
        if t == target:
            break
    else:
        data_files.append((target, []))
        f = data_files[-1][1]
    if source not in f:
        f.append(source)
358989
def put_string(self, content, destination_s3_path, **kwargs):
        
        self._check_deprecated_argument(**kwargs)
        (bucket, key) = self._path_to_bucket_and_key(destination_s3_path)

        # put the file
        self.s3.meta.client.put_object(
            Key=key, Bucket=bucket, Body=content, **kwargs)
72182
def insert_file(self, f, namespace, timestamp):
        
        doc = f.get_metadata()
        doc["content"] = f.read()
        self.doc_dict[f._id] = Entry(doc=doc, ns=namespace, ts=timestamp)
656633
public function replaceFile($old, $new, array $content)
    {
        $oldFileContent = file_get_contents($old);
        file_put_contents($new, vsprintf($oldFileContent, $content));
        unlink($old);
    }
226136
def apply_and_save(self):
        """"""
        patches = self.patches

        content = None
        with open(self.IN_PATH) as f_in:
            # As setup.py.in file size is 2.4 KByte.
            # it's fine to read entire content.
            content = f_in.read()

        # Replace words.
        for key in self.replaced_word_dict:
            content = content.replace(key, self.replaced_word_dict[key])

        # Apply patches.
        out_patches = []
        for patch in patches:
            pattern = re.compile(patch['src'], re.MULTILINE)
            (content, subs_num) = re.subn(pattern, patch['dest'],
                                          content)
            if subs_num > 0:
                patch['applied'] = True
            out_patches.append(patch)

        for patch in out_patches:
            if patch.get('required') and not patch.get('applied'):
                Log.warn('Patch not applied {0}'.format(patch['src']))

        with open(self.OUT_PATH, 'w') as f_out:
            f_out.write(content)

        self.pathces = out_patches
        # Release content data to make it released by GC quickly.
        content = None
776153
def appendData(self, content):
		
		if self.pcdata is not None:
			self.pcdata += content
		else:
			self.pcdata = content
904670
def _update_file_args(self, file_mapping):
        """"""
        for key, value in self.args.items():
            new_value = file_mapping.get(value, value)
            if new_value != value:
                self.args[key] = new_value
429010
function replace(file, options) {
  var contents = file.contents;
  var copied = 0;

  var processed = translate(options, contents, copied, file.path);

  var files = [];
  for (var lang in processed) {
    var params = {};
    params.ext = path.extname(file.path).substr(1);
    params.name = path.basename(file.path, path.extname(file.path));
    params.path = file.path.substring(file.base.length, file.path.lastIndexOf(path.sep));
    params.lang = lang;

    var filePath = options.filename;
    for (var param in params) {
      filePath = filePath.replace('${' + param + '}', params[param]);
    }
    filePath = path.join(file.base,filePath);

    var newFile = new gutil.File({
      base: file.base,
      cwd: file.cwd,
      path: filePath,
      contents: new Buffer(processed[lang], 'utf8')
    });
    files.push(newFile);
  }

	return files;
}
128628
def copy_and_replace(file_in, file_out, mapping, **kwargs):
    '''
    
    '''
    separator = '@@'
    if 'separator' in kwargs:
        separator = kwargs['separator']
    file_in = open(file_in, 'r')
    file_out = open(file_out, 'w')
    s = file_in.read()
    for find, replace in mapping:
        find = separator + find + separator
        print(u'Replacing {0} with {1}'.format(find, replace))
        s = s.replace(find, replace)
    file_out.write(s)
756960
def update_file(filename, items):
    '''
    '''
    # TODO: Implement something in the templates to denote whether the value
    # being replaced is an XML attribute or a value. Perhaps move to dyanmic
    # XML tree building rather than string replacement.
    should_escape = filename.endswith('addon.xml')

    with open(filename, 'r') as inp:
        text = inp.read()

    for key, val in items.items():
        if should_escape:
            val = saxutils.quoteattr(val)
        text = text.replace('{%s}' % key, val)
    output = text

    with open(filename, 'w') as out:
        out.write(output)
1129242
def put_str(content, path, share='C$', conn=None, host=None, username=None, password=None):
    '''
    
    '''
    if HAS_SMBPROTOCOL:
        return _put_str_smbprotocol(
            content, path, share, conn=conn, host=host,
            username=username, password=password
        )
    elif HAS_IMPACKET:
        return _put_str_impacket(
            content, path, share, conn=conn, host=host, username=username, password=password
        )
    raise MissingSmb("SMB library required (impacket or smbprotocol)")