2017-01-26 24 views
0

インターネットからzipファイルを取得し、そこからストリームを使用してディスクから1つのファイルを抽出するスクリプトをプログラムしようとしています。圧縮ファイルが大きすぎます

問題は、抽出されたファイルが大きすぎることです。

  • 圧縮サイズ:30キロバイト
  • オリジナルのサイズ:373キロバイト
  • 解凍後のサイズ:825キロバイト

誰かが私のコードで間違っているものを見つける私を助けることができれば、私は喜んでいるだろう。私はストリームを使って答えを得たいと思っています。

(今日のように)ダウンロードされたファイルは以下のとおりです。https://bitbucket.org/rude/love/downloads/love-0.10.2-win64.zip

マイコード:

### Download current LOVE framework executable ### 

# By default PowerShell supports only SSL3 and TLS1.0, add TLS1.1 and TLS1.2 support. 
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' 

# Get current version of the LOVE framework 

$request = Invoke-WebRequest "https://love2d.org/" 
$downloadUri = (Select-String -InputObject $request.Content -Pattern "https://bitbucket\.org/rude/love/downloads/love-.*-win64\.zip").Matches[0].Value 
$loveBinaryStream = (Invoke-WebRequest $downloadUri).RawContentStream 

# Extract love.exe 
Add-Type -AssemblyName System.IO.Compression 
$zipArchive = New-Object System.IO.Compression.ZipArchive($loveBinaryStream) 
$zipEntry = $zipArchive.Entries | ? { $_.Name -eq "love.exe" } 

$stream = $zipEntry.Open() 
$sr = New-Object System.IO.StreamReader($stream) 
$sw = New-Object System.IO.StreamWriter("love.exe") 
$sw.Write($sr.ReadToEnd()) 
$sw.Close() 
$sr.Close() 
$stream.Close() 
+1

出力ファイルの内容を確認しましたか?私はFormat-Hexを使って何が出力されているのかを見てみたいと思います。 –

答えて

0

私はそれはエンコードの問題のいくつかのようなものだったと考えています。この代わりにとにかく

、この

# Save to disk 
$sw = [System.IO.FileStream]::new($tempLovePath, [System.IO.FileMode]::Create) 
$stream = $zipEntry.Open() 
$stream.CopyTo($sw) 
$stream.Close() 
$sw.Close() 

ため

$stream = $zipEntry.Open() 
$sr = New-Object System.IO.StreamReader($stream) 
$sw = New-Object System.IO.StreamWriter("love.exe") 
$sw.Write($sr.ReadToEnd()) 
$sw.Close() 
$sr.Close() 
$stream.Close() 

は、問題を解決しました。

1
### Download current LOVE framework executable ### 

# By default PowerShell supports only SSL3 and TLS1.0, add TLS1.1 and TLS1.2 support. 
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' 

# Get current version of the LOVE framework 

$request = Invoke-WebRequest "https://love2d.org/" 
$downloadUri = (Select-String -InputObject $request.Content -Pattern "https://bitbucket\.org/rude/love/downloads/love-.*-win64\.zip").Matches[0].Value 
$loveBinaryStream = (Invoke-WebRequest $downloadUri).RawContentStream 

# Extract love.exe 
Add-Type -AssemblyName System.IO.Compression 
Add-Type -AssemblyName system.io.compression.filesystem # for the System.IO.Compression.ZipFileExtensions 
$zipArchive = New-Object System.IO.Compression.ZipArchive($loveBinaryStream) 
$zipEntry = $zipArchive.Entries | ? { $_.Name -eq "love.exe" } 
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry, "path_to_file") 
+0

ありがとう、良いアドバイス。しかし、私はストリームを使いたいです。申し訳ありませんが、私はそれについて言及しませんでした。あなたはそれについても考えているのですか? – Daniel

関連する問題