然后,我可以将档案转换到B64,然后回来,我想压缩数据,然后再转换到B64。 如果我能够在转换过程中找到某个地方的话,那么Gzip 确实必须使用,任何类型的压缩或缩小规模都是罚款,我想压缩是答案,因为B64在储存时使用的空间超过了原始档案。
<>可见> 档案——和; B64 + B64 -> 档案(在无经济档案的情况下工作罚款)
Goal: File->Compression->B64 + B64->Decompression->File (With no temp files)
非压缩工作实例
FileToB64Text.ps1
[Convert]::ToBase64String([IO.File]::ReadAllBytes( test.pdf )) | Out-File testpdf.txt"
B64TextToFile.ps1
$file = Get-Content testpdf.txt
[IO.File]::WriteAllBytes( test2.pdf , [Convert]::FromBase64String( $file ))
I stumbled across another way to do this with compression, which seems great since B64 conversion increases filesize, but the example is using TextToB64/B64ToText instead of FilesToB64/B64ToFiles. A way to use files as an initial input and final output AND having the compression is what I am trying to achieve.
<>CompressAndEncode.ps1
$s = Get-Content DecodedText.txt
$ms = New-Object System.IO.MemoryStream
$cs = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Compress)
$sw = New-Object System.IO.StreamWriter($cs)
$sw.Write($s)
$sw.Close();
$s = [System.Convert]::ToBase64String($ms.ToArray()) | Out-File b64output.txt
DecodeAndDecompress.ps1
$encodedstring = Get-Content b64output.txt
$data = [System.Convert]::FromBase64String("$encodedstring")
$ms = New-Object System.IO.MemoryStream
$ms.Write($data, 0, $data.Length)
$ms.Seek(0,0) | Out-Null
$sr = New-Object System.IO.StreamReader(New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Decompress))
$sr.ReadToEnd() | Out-File DecodedText.txt