/** * Pack file stream * @internal * * @param int $compr compression type * @param array $file file data * @return array array(handle, path) */ protected function _pack_stream($compr, $file) { // get stream $stream = new KZipStream($file[0] === self::FILE_REAL ? $this->handle : null, $file); // create temporary file $tmp = _tmpFile(); // read while (!$stream->eof()) { // load chunk if ($compr === self::COMPR_NONE) { $read = $stream->read(); } else { // compress $read = $stream->read(self::STREAM_CBUFFER); switch ($compr) { case self::COMPR_DEFLATE: $read = gzdeflate($read, $this->compr_level); break; } $read = pack('V', strlen($read)) . $read; } // write to temporary file fwrite($tmp[0], $read); $read = ''; } // free stream, reset and return tmpfile $stream->free(); fseek($tmp[0], 0); return $tmp; }
/** * Export database tables (structure only) * @param array|null $tables array of table names (with prefix) or null (= all) * @return array temporary file array(handle, path) containing the table structure */ public function exportTables($tables = null) { // find all tables if (!isset($tables)) { $tables = $this->_get_tables(); } // get temporary file $file = _tmpFile(); // export tables $sep = chr(0); $prefix = chr(1); $prefix_off = strlen(_mysql_prefix) + 1; for ($i = 0; isset($tables[$i]); ++$i) { $q = DB::rown(DB::query('SHOW CREATE TABLE `' . $tables[$i] . '`')); $table = substr($tables[$i], $prefix_off); fwrite($file[0], 'DROP TABLE IF EXISTS `' . $prefix . '-' . $table . '`' . $sep); fwrite($file[0], str_replace('CREATE TABLE `' . $tables[$i] . '`', 'CREATE TABLE `' . $prefix . '-' . $table . '`', $q[1]) . $sep); } // return return $file; }