save the table as a file
 @param String name of output file. If nil, user is prompted
 Currently, tabs are used as delimiter, but this could be based on input
 separator, or prompted.
513242
def save_as outfile
      _t = "(all rows)"
      if @selected_indices.size > 0
        _t = "(selected rows)"
      end
      unless outfile
        outfile = get_string "Enter file name to save #{_t} as "
        return unless outfile
      end

      # if there is a selection, then write only selected rows
      l = nil
      if @selected_indices.size > 0
        l = []
        @list.each_with_index { |v,i| l << v if @selected_indices.include? i }
      else
        l = @list
      end

      File.open(outfile, 'w') {|f|
        l.each {|r|
          line = r.join "\t"
          f.puts line
        }
      }
    end
169033
public function save(string $path, string $name, ?string $extension = null, int $quality = 100): bool
    {
        if (false === is_dir($path)) {
            mkdir($path, 0777, true);
        }
        if (null === $extension) {
            /** @var string $extension */
            $extension = $this->extension;
        }
        if (true === $this->encrypted) {
            file_put_contents($path . $name . '.' . self::FORMAT_WD_IMAGE, $this->workingData);
            return true;
        } elseif (0 !== imagetypes()) {
            $filename = $path . $name . '.' . $extension;
            switch (strtolower($extension)) {
                case self::FORMAT_GIF:
                    imagegif($this->workingData, $filename);
                    break;
                case self::FORMAT_JPEG:
                case self::FORMAT_JPG:
                    imagejpeg($this->workingData, $filename, $quality);
                    break;
                case self::FORMAT_PNG:
                    imagepng($this->workingData, $filename, (int)round(9 - ((9 * $quality) / 100)));
                    break;
                default:
                    throw new ImageException('Unsupported file type');
            }
            return false;
        }
    }
453516
def write_file(self, name, path=None):
        """"""

        if path is None:
            path = name

        self.zf.write(path, name)
1158233
public function save()
    {
        $file = $this->getFilename() . '.' . $this->getFileExtension();

        // Add save path if given
        if (null !== $this->savePath) {
            $file = $this->savePath . $file;
        }

        file_put_contents(
            $file,
            $this->getOutput()
        );
    }
56292
protected function writeMigration($name, $extension, $table, $create)
    {
        $path = $this->creator->create($name, $extension, $table, $create);

        $file = pathinfo($path, PATHINFO_FILENAME);

        $this->info("Created migration: $file");
    }
1196044
public void generateOutput(String outputFileName) throws IOException {
        FileOutputStream stream = null;
        OutputStreamWriter writer = null;
        try {
            stream = new FileOutputStream(outputFileName);
            writer = new OutputStreamWriter(stream, charset);
            generateOutput(writer);
        } finally {
            if (writer != null) {
                writer.close();
            }
            if (stream != null) {
                stream.close();
            }
        }
    }
1271068
def store(self):
        
        output = tempfile.NamedTemporaryFile(suffix='.json')
        try:

            def write(o):
                line = json.dumps(o, default=json_default)
                return output.write(line + '\n')

            yield write

            output.seek(0)
            log.info("Uploading generated table (%s)...", self._obj)
            self.save_file(output.name, destructive=True)
        finally:
            try:
                output.close()
            except:
                pass
234303
private function _saveSd ($path, $name, $file)
		{
			$this->_save($path . DIRECTORY_SEPARATOR . self::F_SD . DIRECTORY_SEPARATOR . $name, $file, self::F_SD);
		}
1032457
def save(self, name, file):
        
        # Get the proper name for the file, as it will actually be saved.
        if name is None:
            name = file.name

        if not hasattr(file, 'chunks'):
            file = File(file, name=name)

        name = self.get_available_name(name)
        name = self._save(name, file)

        # Store filenames with forward slashes, even on Windows
        return name.replace('\\', '/')
853587
public function addFormField(string $name): void
    {
        $options = $this->formOptions['fields'][$name];
        $wrapper = $this->createWrapper();
        $label = '';

        if (isset($options['label']['text'])) {
            $label = $this->createLabel($options['label']['text'], $name);

            unset($options['label']['text']);
        }

        $input = HtmlTag::createElement('input')
            ->set('type', $options['input']['type'] ?? 'text')
            ->set('id', $name)
            ->set('name', $name);

        $caption = '';

        if (isset($options['caption']['text'])) {
            $input->set('aria-describedby', $name . '_caption');
            $caption = $this->createCaption($options['caption']['text'], $name);

            unset($options['caption']['text']);
        }

        $elements = [
            'wrapper' => $wrapper,
            'label'   => $label,
            'input'   => $input,
            'caption' => $caption
        ];

        foreach ($elements as $name => $element) {
            $$name = $this->assignOptionsToElement($options, $name, $element);
        }

        if (in_array($options['input']['type'] ?? 'text', ['checkbox', 'radio', 'file'])) {
            $wrapper->addElement($input);
            $wrapper->addElement($label);
        } else {
            $wrapper->addElement($label);
            $wrapper->addElement($input);
        }

        $wrapper->addElement($caption);

        echo $wrapper;
    }
538725
public function save($pFilename = null) {
		// garbage collect
		$this->_phpExcel->garbageCollect();

		$saveDebugLog = PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->getWriteDebugLog();
		PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->setWriteDebugLog(FALSE);
		$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
		PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);

		// Build CSS
		$this->buildCSS(!$this->_useInlineCss);

		// Open file
		$fileHandle = fopen($pFilename, 'wb+');
		if ($fileHandle === false) {
			throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing.");
		}

		// Write headers
		fwrite($fileHandle, $this->generateHTMLHeader(!$this->_useInlineCss));

		// Write navigation (tabs)
		if ((!$this->_isPdf) && ($this->_generateSheetNavigationBlock)) {
			fwrite($fileHandle, $this->generateNavigation());
		}

		// Write data
		fwrite($fileHandle, $this->generateSheetData());

		// Write footer
		fwrite($fileHandle, $this->generateHTMLFooter());

		// Close file
		fclose($fileHandle);

		PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
		PHPExcel_Calculation::getInstance($this->_phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog);
	}
457510
public function save($filename, $formatOutput = true)
    {
        // Format output
        if ($formatOutput === true) {
            $this->dom->formatOutput = true;
        }

        return $this->dom->save($filename);
    }
1317954
def save(self, name=None, path=None):
        
        if path :
            name = os.path.join(path,name)

        try:
            self._create_table_xml_file(self.etree, name)
        except (Exception,) as e:
            print(e)
            return False

        return True
510399
public static function write_log($name, $line)
    {
        if (!is_string($line)) {
            $line = var_export($line, true);
        }

        $date_format = $log_driver = $session_key = null;
        if (self::$instance) {
            $date_format = self::$instance->config->get('log_date_format');
            $log_driver  = self::$instance->config->get('log_driver');
            $session_key = intval(self::$instance->config->get('log_session_id', 8));
        }

        $date = rcube_utils::date_format($date_format);

        // trigger logging hook
        if (is_object(self::$instance) && is_object(self::$instance->plugins)) {
            $log = self::$instance->plugins->exec_hook('write_log',
                array('name' => $name, 'date' => $date, 'line' => $line));

            $name = $log['name'];
            $line = $log['line'];
            $date = $log['date'];

            if ($log['abort']) {
                return true;
            }
        }

        // add session ID to the log
        if ($session_key > 0 && ($sess = session_id())) {
            $line = '<' . substr($sess, 0, $session_key) . '> ' . $line;
        }

        if ($log_driver == 'syslog') {
            $prio = $name == 'errors' ? LOG_ERR : LOG_INFO;
            return syslog($prio, $line);
        }

        // write message with file name when configured to log to STDOUT
        if ($log_driver == 'stdout') {
            $stdout = "php://stdout";
            $line = "$name: $line";
            return file_put_contents($stdout, $line, FILE_APPEND) !== false;
        }

        // log_driver == 'file' is assumed here

        $line = sprintf("[%s]: %s\n", $date, $line);

        // per-user logging is activated
        if (self::$instance && self::$instance->config->get('per_user_logging') && self::$instance->get_user_id()) {
            $log_dir = self::$instance->get_user_log_dir();
            if (empty($log_dir) && !in_array($name, array('errors', 'userlogins', 'sendmail'))) {
                return false;
            }
        }

        if (empty($log_dir)) {
            if (!empty($log['dir'])) {
                $log_dir = $log['dir'];
            }
            else if (self::$instance) {
                $log_dir = self::$instance->config->get('log_dir');
            }
        }

        if (empty($log_dir)) {
            $log_dir = RCUBE_INSTALL_PATH . 'logs';
        }

        return file_put_contents("$log_dir/$name", $line, FILE_APPEND) !== false;
    }
738368
public function save($fileName, $values, $map = null) {
		if ($map !== null) {
			$output = $this->createOutputWithMap($values,$map);
		} else {
			$output = $this->createOutput($values);
		}

		$this->saveToFile($fileName, $output);
	}
1302613
def save_page(file_name = nil)
        file_name ||= Time.now.strftime("%Y%m%d%H%M%S") + ".html"
        puts "about to save page: #{File.expand_path(file_name)}" if $DEBUG
        File.open(file_name, "w").puts page_source
      end
913095
public static function create($name = '', array $header = array(), Temp $temp = null)
	{

		if ($temp == null) {
			$temp = new Temp('csv-table');
		}

		$tmpFile = $temp->createTmpFile($name);
		$csvFile = new self($tmpFile->getPathname());
		// Write header
		if (!empty($header)) {
			$csvFile->writeRow($header);
		}

		// Preserve Temp to prevent deletion!
		$csvFile->setTemp($temp);

		$csvFile->name = $name;

		return $csvFile;
	}