Escribe en un fichero sus Bytes, crea el objeto File

@param $data_bytes
@param $extension
@return File
972187
private function writeFileBytes($data_bytes, $extension, $field, $classFileString) {
        $dir_rel = "uploads" . DIRECTORY_SEPARATOR . "gallery" . DIRECTORY_SEPARATOR;
        $dir = $this->createDir($this->getRoot(). DIRECTORY_SEPARATOR ."web" . DIRECTORY_SEPARATOR . $dir_rel);
        $file = new $classFileString;

        // Obtenemos un nombre único
        $name=uniqid("AppFileUniqSystem", true);
        $name = $field . "_" . md5($name) .'.' . $extension;

        // Calculamos el nombre de la ruta completo y relativo, metemos los bytes
        $file_abs_name = $dir . $name;
        $file_rel_name = $dir_rel. $name;
        $this->bytes_to_file($data_bytes, $file_abs_name);

        // Guardamos los datos en File
        $file->setPath($file_rel_name);

        // Devolvemos el File
        return $file;
    }
85902
public static function saveImage($table_name, $field_name, $file_name, $row_id=null, $extension=null) {
		return FileController::saveImage($table_name, $field_name, $file_name, $row_id, $extension);
	}
77958
private function checkFileExtension($extension)
    {
        $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp');

        in_array(strtolower($extension), $valid)
            or $this->raiseError('Not a valid file extension.');

        return $this;
    }
1351182
public static function inc($path, $extensionId = null, $data = array()) {
        $context = \Context::getInstance();
        if (!is_null($extensionId) && $extensionId != $context->getExtensionName()) {
            // template is within different extension, change context
            $formerContext = $context->getExtensionName();
            $context->setExtensionName($extensionId);
        }

        if(count($data) > 0){
            \RenderContext::pushContext($data);
        }
        
        $absPath = self::getTemplate($path, $extensionId);
        if (file_exists($absPath)) {
            include($absPath);
        } else {
            \common_Logger::w('Failed to include "'.$absPath.'" in template');
        }
        // restore context
        if (isset($formerContext)) {
            $context->setExtensionName($formerContext);
        }
    }
451051
static function bytes($bytes = Constants::BYTES)
    {
        # Test the length for validity.
        Helpers::rangeCheck($bytes, Constants::BYTES_MAX, Constants::BYTES_MIN, 'Entropy', 'bytes');

        return \Sodium\randombytes_buf($bytes);
    }
571835
public function encode(array $data, string $contentType): string
    {
        if (isset($this->encoderTypes[$contentType])) {
            return $this->encoderTypes[$contentType]->encode($data);
        }

        throw SerializerLogicException::createMissingContentType($contentType);
    }
319482
private function fileExtensionAsImage(string $extension): ResponseInterface
    {
        $extension = '.' . strtolower($extension);

        $svg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect width="100" height="100" fill="#88F" /><text x="5" y="60" font-family="Verdana" font-size="30">' . $extension . '</text></svg>';

        return response($svg, StatusCodeInterface::STATUS_OK, [
            'Content-Type'   => 'image/svg+xml',
            'Content-Length' => strlen($svg),
        ]);
    }
1064312
protected function writeFileExport( string $file, $data, string $data_name = 'data' )
	{
		return $this->write(
			$file,
			'<' . "?php defined('ELS_CMS') || exit('Not access'); \n" . PhpExport::getInstance()->data($data, $data_name, true, true),
			false
		);
	}
1079453
public function downloadAction(Request $request, DataExport $dataExport)
    {
        $explode = explode('/', $dataExport->getPath());
        $fileName = end($explode);
        $file = $this->getParameter('kernel.root_dir'). '/../web/uploads/data_export/'.$dataExport->getPath();
        $response = new BinaryFileResponse($file);
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $fileName);

        return $response;
    }
874659
public function render(DataBuilder $data_builder, string $filetype, $parameters, array $data = [])
    {
        $result = new Result();

        try {
            $bag = new Bag($parameters);

            $bag->set('content', $this->renderRaw($filetype, strval($bag->get('content')), $data));

            $result->setResources(new Collection([$bag->toArray()]));
        } catch (\Twig_Error $e) {
            $e = new Exceptions\TemplateRenderException($e->getRawMessage().' on line '.$e->getTemplateLine());

            $result->addErrors(new Collection([$e]));
        }

        return $result;
    }
728394
public function sendWithMetadata($address, $amount, $dataHex)
    {
        return $this->jsonRPCClient->execute("sendwithmetadata", array($address, $amount, $dataHex));
    }
893118
public static function mapExtensionToType($dataFile) {
        $ext = substr(strrchr($dataFile, '.'), 1);
        $ext = strtolower($ext);
        switch ($ext) {
            case 'xls':
            case 'xlsx':
                return 'Excel';
            break;
            case 'json':
                return 'Json';
            break;
            default:
                throw new Garp_Content_Import_Exception("Could not find importer for type $ext");
            break;
        }
    }
565529
public function stream_write($data)
    {
        if ($this->_upload === null) {
            return false;
        }
        $this->_upload->addContent($data);
        $result = StringHelper::byteLength($data);
        $this->_pointerOffset += $result;
        return $result;
    }
314549
public function readData($bytes, $extra = self::EOL_LENGTH)
    {
        $this->ensureConnected();

        $data = $this->socket->readData($bytes + $extra);

        return substr($data, 0, $bytes);
    }
1124510
protected static function getFileTypeByExtension(string $extension): int
    {
        switch ($extension) {
            case 'png':
            case 'jpg':
                return FileInterface::TYPE_STATIC_IMAGE;

            case 'gif':
                return FileInterface::TYPE_ANIMATED_IMAGE;

            case 'webm':
            case 'mp4':
            case 'zip':
                return FileInterface::TYPE_VIDEO;

            default:
                throw new InvalidArgumentException(sprintf(
                    'Unknown file type: %s',
                    $extension
                ));
        }
    }
989903
def bytes2zip(bytes):
    
    if hasattr(bytes, "read"):
        buff = TemporaryFile()
        archive = gzip.GzipFile(fileobj=buff, mode='w')
        for b in bytes:
            archive.write(b)
        archive.close()
        buff.seek(0)
        from pyLibrary.env.big_data import FileString, safe_size
        return FileString(buff)

    buff = BytesIO()
    archive = gzip.GzipFile(fileobj=buff, mode='w')
    archive.write(bytes)
    archive.close()
    return buff.getvalue()
861436
private function buildData($originalName, $extension)
    {
        $tmpDirectory = $this->getApplication()->getTemporaryDir();
        $fileName = md5($originalName . uniqid('', true)) . '.' . $extension;

        $data = [
            'originalname' => $originalName,
            'path'         => $tmpDirectory . DIRECTORY_SEPARATOR . $fileName,
            'filename'     => $fileName
        ];

        return $data;
    }