如何将“数据:文本/css;base64”字符串转换为普通/文本css文件?

时间:2021-02-16 16:02:32

I have this data string what contain a CSS file:

我有一个数据字符串包含一个CSS文件:

data:text/css;base64,H4sIAAAAAAAAA8VY227bOBB9lr6CC6NoG1iOLMVp4zzt237AvhuUREusKVGg6MRJkH/fIakLqUuStthdFCnk4cxw5syFQ/pX6AXVOMtole9ReI9KLHJa6U9+loxWZI8qXpF79Or7Cc+e0IvvJTg95YKfqyygJc6B5SzYl8+bzTUt8+sk3/yo889f7x1GQWqCpVLWfrrLDX0GNSl/IMJdwFLitChJBbJHeiHZvQ+WbBKw+8grGTwSmhewlnCWKSM3KaxIcpEBZjQHT1IQBaVqiY2WGDlKvSBGC0Lp1CtHJXNkXJnesx/FQBxYU6bIKSNYKHNkoTFbpWAlBhxFUBCcafi4yOAnsEhe7tG2vqCGM5qhVRiG4L0VD98zARmYw/riALRHq+PxaEBRW4G3jwLXap8SX4JHmskCxOLQCPbxRfgsORBaN3SMR1vPbbJSThCx9leM5zzhlzXACl8ZfVBb2vKvhkeRizZIN8aI1ihjwavv2Rq8mdj5HsBb4YcEiwG/3mbbzI7EL0FT4Iw/9qQRjqHZuFW6GYJ0ZGearZeXULsQpJwxXDdEG+3g1ipGjOo1YORg7SqOY1j0pllrS+wLVQJazoE/3O3iJDasI16sufttIFDoD1rWXEhcqSprIbXxGDF0aQpor/uvQElBdHNBoXr5Y9ADMQ20v1JcDj2CUHcodyq0oV0uRJFJBhe7hXzvtVBJSoM4b6ikXBUrYVjSBxXkQXmb7n2+D3psRQwnhBn4psnujbiDFhjDn9GmZvipz68xc0ZSLoKKmKS2zMUJFPtZahmvczP6ZszV2aF0ihIztN3WEv2NC17iNfpTUMzW6C/CHoikKVAaXDVBQwTVxvYJYJqIhcWu1W2ngReotqP/C7W/a8XhefNUTZnlHYh6C0YkFGzQ1DjVId22W19fQconJ2qyKmik4CdiWp+WvbpeQjA5A0JV8yEUQwtCVVloe/s7AP4HeHUxitt0VV28gaNAdRWV8+a7iLT7lmNx9BOOWZ3h3h+7FSkHImMVOG5MnSVqwhznQFPqxykQjapcN4ZoKGvjYt172I4C2++1dOS2s3LYabGtCR8I3CxxNmyTqKkYHTmXOkvX1jfCAuBnxO2PSJff6wzfvpJFkBaUZV+2X505TMugd2Sid2WKyDGviN3hzT5W3ByxS+jm45k2DI/+bNxGxpkZxWn3U6yM0XNsTrZEKlvUQSQLQqps4qjxq/Py7u4Ofs1OGoPdO2dg0m6E6p+ZtaCdNQWvDycsSc4Bl0NKVTZ0dNBWkpMiKltsQL9/HFCnaBYsnjdG4oThqTmaPD6/PUYb1ZOfGFkal7r4eUtbwTiytlad7do5yEVS1Wk3yFkTcNujevN2fb0vqLYHpqm6NE1H4lO7kZo88VvWawa9RX/qJ4ynJ2VpN2CH4SdnAIm7TuVvjLpAoYyDE6lHV6hfvRkNh+Eu/KT+TIAmu0EnrlzjaaUudsGSD/OnrHPI/vqYMmrV4yHF6mftyPYvd/OlkeUjE4sFd59W/chnd6cbc5YtXG16JXOiurG9VQA6OzdwITnxBosEjzN1OdjG0X4EaQ9q5177cztvzP3s3b13Js9mTvu5y9F7KfO/5Md7sOA36rCrpJvl5nZm+EcGYy/OtUQXs10bs4U7pO+tjALY7lDh/KkkgsiEVLN31FXKaHoqicLv7bC5bwSdNbN3LGdCg+bAaJk73X/XNX9LqXsdfe3dOOSYQd/Ak3cB9RIzEQKxmlTPEosDQC7PzbMpJtd4t4OPLsKtZ/HYMz2ztg8myjNa1Wd5KElVPdGGgIPIqSqkedT+I/rw+qKxMliMn5dUO2CkPjMCtx5kPeLcRLGrJFzQ4G8YrvkzHyan0RjmX1/BCZlCp24QNDJ/1f14GQ9ucTe4QYEJkvCLYllKFNuM/pXn2+6N0QV8faSmvpT+9rZn5/ztLVgxyY/D4VCzcwMxPYQ9ymPWmWdAZ/nV/we8bspA/xQAAA==

How can I convert this back to plain text CSS file via PHP or Perl?

如何通过PHP或Perl将其转换为纯文本CSS文件?

2 个解决方案

#1


3  

The base64 decoded data is gzip compressed.

base64解码数据为gzip压缩。

#!/usr/bin/perl
use strict;
use warnings;
use v5.10;

use URI          qw[];
use Gzip::Faster qw[gunzip];

my $uri = 'data:text/css;base64,
H4sIAAAAAAAAA8VY227bOBB9lr6CC6NoG1iOLMVp4zzt237AvhuUREusKVGg6MRJkH/fIakLqUuSt
thdFCnk4cxw5syFQ/pX6AXVOMtole9ReI9KLHJa6U9+loxWZI8qXpF79Or7Cc+e0IvvJTg95YKfqy
ygJc6B5SzYl8+bzTUt8+sk3/yo889f7x1GQWqCpVLWfrrLDX0GNSl/IMJdwFLitChJBbJHeiHZvQ+
WbBKw+8grGTwSmhewlnCWKSM3KaxIcpEBZjQHT1IQBaVqiY2WGDlKvSBGC0Lp1CtHJXNkXJnesx/F
QBxYU6bIKSNYKHNkoTFbpWAlBhxFUBCcafi4yOAnsEhe7tG2vqCGM5qhVRiG4L0VD98zARmYw/riA
LRHq+PxaEBRW4G3jwLXap8SX4JHmskCxOLQCPbxRfgsORBaN3SMR1vPbbJSThCx9leM5zzhlzXACl
8ZfVBb2vKvhkeRizZIN8aI1ihjwavv2Rq8mdj5HsBb4YcEiwG/3mbbzI7EL0FT4Iw/9qQRjqHZuFW
6GYJ0ZGearZeXULsQpJwxXDdEG+3g1ipGjOo1YORg7SqOY1j0pllrS+wLVQJazoE/3O3iJDasI16s
ufttIFDoD1rWXEhcqSprIbXxGDF0aQpor/uvQElBdHNBoXr5Y9ADMQ20v1JcDj2CUHcodyq0oV0uR
JFJBhe7hXzvtVBJSoM4b6ikXBUrYVjSBxXkQXmb7n2+D3psRQwnhBn4psnujbiDFhjDn9GmZvipz6
8xc0ZSLoKKmKS2zMUJFPtZahmvczP6ZszV2aF0ihIztN3WEv2NC17iNfpTUMzW6C/CHoikKVAaXDV
BQwTVxvYJYJqIhcWu1W2ngReotqP/C7W/a8XhefNUTZnlHYh6C0YkFGzQ1DjVId22W19fQconJ2qy
Kmik4CdiWp+WvbpeQjA5A0JV8yEUQwtCVVloe/s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off the header and then parse the Base64:

我们只需要从header中删除,然后解析Base64:

<?php
function convertCss($fc, $isFile = FALSE){
    if($isFile){
        $lines = explode(",", file_get_contents($fc));
    } else {
        $lines = explode(",", $fc);
    }
    $css = "";
    if(lines[1] == "base64"){
        $css = base64_decode($lines[2]);
    } else {
        $css = FALSE;
    }
    return $css;
}
?>

Paramters

的目的

fc - File Content, pass Base64 encoded data to the function.

fc -文件内容,将Base64编码的数据传递给函数。

isFile - When TRUE, reads Base64 encoded data from File Path.

isFile—当为真时,从文件路径读取Base64编码的数据。

Return Values

返回值

Returns the CSS decoded or FALSE on error.

返回CSS解码或错误的错误。

#1


3  

The base64 decoded data is gzip compressed.

base64解码数据为gzip压缩。

#!/usr/bin/perl
use strict;
use warnings;
use v5.10;

use URI          qw[];
use Gzip::Faster qw[gunzip];

my $uri = 'data:text/css;base64,
H4sIAAAAAAAAA8VY227bOBB9lr6CC6NoG1iOLMVp4zzt237AvhuUREusKVGg6MRJkH/fIakLqUuSt
thdFCnk4cxw5syFQ/pX6AXVOMtole9ReI9KLHJa6U9+loxWZI8qXpF79Or7Cc+e0IvvJTg95YKfqy
ygJc6B5SzYl8+bzTUt8+sk3/yo889f7x1GQWqCpVLWfrrLDX0GNSl/IMJdwFLitChJBbJHeiHZvQ+
WbBKw+8grGTwSmhewlnCWKSM3KaxIcpEBZjQHT1IQBaVqiY2WGDlKvSBGC0Lp1CtHJXNkXJnesx/F
QBxYU6bIKSNYKHNkoTFbpWAlBhxFUBCcafi4yOAnsEhe7tG2vqCGM5qhVRiG4L0VD98zARmYw/riA
LRHq+PxaEBRW4G3jwLXap8SX4JHmskCxOLQCPbxRfgsORBaN3SMR1vPbbJSThCx9leM5zzhlzXACl
8ZfVBb2vKvhkeRizZIN8aI1ihjwavv2Rq8mdj5HsBb4YcEiwG/3mbbzI7EL0FT4Iw/9qQRjqHZuFW
6GYJ0ZGearZeXULsQpJwxXDdEG+3g1ipGjOo1YORg7SqOY1j0pllrS+wLVQJazoE/3O3i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qicLv7bC5bwSdNbN3LGdCg+
bAaJk73X/XNX9LqXsdfe3dOOSYQd/Ak3cB9RIzEQKxmlTPEosDQC7PzbMpJtd4t4OPLsKtZ/HYMz2
ztg8myjNa1Wd5KElVPdGGgIPIqSqkedT+I/rw+qKxMliMn5dUO2CkPjMCtx5kPeLcRLGrJFzQ4G8Y
rvkzHyan0RjmX1/BCZlCp24QNDJ/1f14GQ9ucTe4QYEJkvCLYllKFNuM/pXn2+6N0QV8faSmvpT+9
rZn5/ztLVgxyY/D4VCzcwMxPYQ9ymPWmWdAZ/nV/we8bspA/xQAAA==';

say gunzip(URI->new($uri)->data);

#2


0  

We just need to lop off the header and then parse the Base64:

我们只需要从header中删除,然后解析Base64:

<?php
function convertCss($fc, $isFile = FALSE){
    if($isFile){
        $lines = explode(",", file_get_contents($fc));
    } else {
        $lines = explode(",", $fc);
    }
    $css = "";
    if(lines[1] == "base64"){
        $css = base64_decode($lines[2]);
    } else {
        $css = FALSE;
    }
    return $css;
}
?>

Paramters

的目的

fc - File Content, pass Base64 encoded data to the function.

fc -文件内容,将Base64编码的数据传递给函数。

isFile - When TRUE, reads Base64 encoded data from File Path.

isFile—当为真时,从文件路径读取Base64编码的数据。

Return Values

返回值

Returns the CSS decoded or FALSE on error.

返回CSS解码或错误的错误。