0
我使用ODP.net和Powershell來獲取Blob壓縮文件。直接讀取blob zip文件而不寫入磁盤
[void][System.Reflection.Assembly]::LoadFile("C:\DLL\Oracle.ManagedDataAccess.dll")
$OracleConnexion = New-Object Oracle.ManagedDataAccess.Client.OracleConnection('User Id=test;Password="test";Data Source=10.2.2.1/TEST')
$OracleConnexion.Open()
$Query=$OracleConnexion.CreateCommand()
$Query.CommandText="SELECT BLOB from MyTable Where ID=01"
$ExecuteQuery=$Query.ExecuteReader()
$Path = "C:\temp"
while ($ExecuteQuery.Read()){
$Localfile = New-Object IO.FileStream("$($Path)\$($ExecuteQuery["LOG_ID"]).zip",[IO.FileMode]::Create)
$Localfile.Write($ExecuteQuery["XML_TRACE"],0,$ExecuteQuery["XML_TRACE"].Length)
$Localfile.Close()
$Zip = [io.compression.zipfile]::OpenRead("$($Path)\$($Executequery["LOG_ID"]).zip")
$Stream = $Zip.Entries.Open()
$Reader = New-Object IO.StreamReader($stream)
$XML = $Reader.ReadToEnd()
$Reader.Close()
$Stream.Close()
$Zip.Dispose()
}
正如你所看到的,第一我寫文件到磁盤$Localfile.Write
然後用[io.compression.zipfile]::OpenRead
我讀我的壓縮文件的內容。
我的代碼工作,但我想直接讀取我的斑點爲壓縮文件,而不將其寫入磁盤,這樣的事情:
while ($ExecuteQuery.Read()){
$Zip = [io.compression.zipfile]::OpenRead($ExecuteQuery["XML_TRACE"]).zip)
$Stream = $Zip.Entries.Open()
$Reader = New-Object IO.StreamReader($stream)
$XML = $Reader.ReadToEnd()
$XML
$Reader.Close()
$Stream.Close()
$Zip.Dispose()
}
編輯:它的工作原理與離子!
while ($ExecuteRequete.Read()){
$ZipStream = New-Object System.IO.Memorystream
$ZipStream.Write($ExecuteRequete["XML_TRACE"],0,$ExecuteRequete["XML_TRACE"].Length)
$ZipStream.Position = 0
$Zip = [Ionic.Zip.ZipFile]::Read($ZipStream)
$Stream = New-Object IO.MemoryStream
$Zip.Extract($Stream)
$stream.Position = 0
$Reader = New-Object IO.StreamReader($stream)
$XML = $Reader.ReadToEnd()
$Reader.Close()
$Stream.Close()
$ZipStream.Dispose()
$Zip.Dispose()
}
你不應該閱讀自己流,嘗試通過'$ ZipStream'到'[Ionic.Zip.ZipFile] ::閱讀($ ZipStream)' –
不錯,謝謝! –
它工作嗎?如果是這樣 - 請接受答案 –