Powershell unzip stream
Is there a built-in cmdlet or some composition thereof that would allow me to start unzipping a file stream as each chunk is downloaded? I have a PowerShell script that needs to download a large (10 GB) file, and I have to wait until it is done right now before it starts expanding...
$wc = New-Object net.webclient
$wc.Downloadfile($appDataSnapshotUri, "%DataSnapshotFileName%.zip") # this can take some time
Expand-Archive -Path "%DataSnapshotFileName%.zip" -DestinationPath Run # so can this
powershell stream
|
show 3 more comments
Is there a built-in cmdlet or some composition thereof that would allow me to start unzipping a file stream as each chunk is downloaded? I have a PowerShell script that needs to download a large (10 GB) file, and I have to wait until it is done right now before it starts expanding...
$wc = New-Object net.webclient
$wc.Downloadfile($appDataSnapshotUri, "%DataSnapshotFileName%.zip") # this can take some time
Expand-Archive -Path "%DataSnapshotFileName%.zip" -DestinationPath Run # so can this
powershell stream
I don't think the .zip compression file format works like that. (A partial download of a .zip file is a corrupt .zip file.)
– Bill_Stewart
Nov 13 '18 at 21:14
1
@Bill_Stewart is 100% right. The index is at the end of a zip called the central directory. Its where the metadeta but most importantly where the start point index of each file stored.
– ArcSet
Nov 14 '18 at 0:02
@ArcSet , @Bill_Stewart yes I have read this as well but I have also been able to do something like this innodejs
even if it is a bit hackerrific. So maybe try a compression format that better supports streaming decompression?
– tacos_tacos_tacos
Nov 14 '18 at 0:10
Is that file on a network drive or ftp or sharepoint? Can you share that node js script?
– Mike Twc
Nov 14 '18 at 4:35
@MikeTwc sure, ill gist it, but for now just see github.com/mhr3/unzip-stream - i use this library
– tacos_tacos_tacos
Nov 14 '18 at 7:57
|
show 3 more comments
Is there a built-in cmdlet or some composition thereof that would allow me to start unzipping a file stream as each chunk is downloaded? I have a PowerShell script that needs to download a large (10 GB) file, and I have to wait until it is done right now before it starts expanding...
$wc = New-Object net.webclient
$wc.Downloadfile($appDataSnapshotUri, "%DataSnapshotFileName%.zip") # this can take some time
Expand-Archive -Path "%DataSnapshotFileName%.zip" -DestinationPath Run # so can this
powershell stream
Is there a built-in cmdlet or some composition thereof that would allow me to start unzipping a file stream as each chunk is downloaded? I have a PowerShell script that needs to download a large (10 GB) file, and I have to wait until it is done right now before it starts expanding...
$wc = New-Object net.webclient
$wc.Downloadfile($appDataSnapshotUri, "%DataSnapshotFileName%.zip") # this can take some time
Expand-Archive -Path "%DataSnapshotFileName%.zip" -DestinationPath Run # so can this
powershell stream
powershell stream
asked Nov 13 '18 at 19:21
tacos_tacos_tacostacos_tacos_tacos
5,886855107
5,886855107
I don't think the .zip compression file format works like that. (A partial download of a .zip file is a corrupt .zip file.)
– Bill_Stewart
Nov 13 '18 at 21:14
1
@Bill_Stewart is 100% right. The index is at the end of a zip called the central directory. Its where the metadeta but most importantly where the start point index of each file stored.
– ArcSet
Nov 14 '18 at 0:02
@ArcSet , @Bill_Stewart yes I have read this as well but I have also been able to do something like this innodejs
even if it is a bit hackerrific. So maybe try a compression format that better supports streaming decompression?
– tacos_tacos_tacos
Nov 14 '18 at 0:10
Is that file on a network drive or ftp or sharepoint? Can you share that node js script?
– Mike Twc
Nov 14 '18 at 4:35
@MikeTwc sure, ill gist it, but for now just see github.com/mhr3/unzip-stream - i use this library
– tacos_tacos_tacos
Nov 14 '18 at 7:57
|
show 3 more comments
I don't think the .zip compression file format works like that. (A partial download of a .zip file is a corrupt .zip file.)
– Bill_Stewart
Nov 13 '18 at 21:14
1
@Bill_Stewart is 100% right. The index is at the end of a zip called the central directory. Its where the metadeta but most importantly where the start point index of each file stored.
– ArcSet
Nov 14 '18 at 0:02
@ArcSet , @Bill_Stewart yes I have read this as well but I have also been able to do something like this innodejs
even if it is a bit hackerrific. So maybe try a compression format that better supports streaming decompression?
– tacos_tacos_tacos
Nov 14 '18 at 0:10
Is that file on a network drive or ftp or sharepoint? Can you share that node js script?
– Mike Twc
Nov 14 '18 at 4:35
@MikeTwc sure, ill gist it, but for now just see github.com/mhr3/unzip-stream - i use this library
– tacos_tacos_tacos
Nov 14 '18 at 7:57
I don't think the .zip compression file format works like that. (A partial download of a .zip file is a corrupt .zip file.)
– Bill_Stewart
Nov 13 '18 at 21:14
I don't think the .zip compression file format works like that. (A partial download of a .zip file is a corrupt .zip file.)
– Bill_Stewart
Nov 13 '18 at 21:14
1
1
@Bill_Stewart is 100% right. The index is at the end of a zip called the central directory. Its where the metadeta but most importantly where the start point index of each file stored.
– ArcSet
Nov 14 '18 at 0:02
@Bill_Stewart is 100% right. The index is at the end of a zip called the central directory. Its where the metadeta but most importantly where the start point index of each file stored.
– ArcSet
Nov 14 '18 at 0:02
@ArcSet , @Bill_Stewart yes I have read this as well but I have also been able to do something like this in
nodejs
even if it is a bit hackerrific. So maybe try a compression format that better supports streaming decompression?– tacos_tacos_tacos
Nov 14 '18 at 0:10
@ArcSet , @Bill_Stewart yes I have read this as well but I have also been able to do something like this in
nodejs
even if it is a bit hackerrific. So maybe try a compression format that better supports streaming decompression?– tacos_tacos_tacos
Nov 14 '18 at 0:10
Is that file on a network drive or ftp or sharepoint? Can you share that node js script?
– Mike Twc
Nov 14 '18 at 4:35
Is that file on a network drive or ftp or sharepoint? Can you share that node js script?
– Mike Twc
Nov 14 '18 at 4:35
@MikeTwc sure, ill gist it, but for now just see github.com/mhr3/unzip-stream - i use this library
– tacos_tacos_tacos
Nov 14 '18 at 7:57
@MikeTwc sure, ill gist it, but for now just see github.com/mhr3/unzip-stream - i use this library
– tacos_tacos_tacos
Nov 14 '18 at 7:57
|
show 3 more comments
2 Answers
2
active
oldest
votes
OK, turns out zip file doesn't need to be fully downloaded to be decompressed, you can compress/decompress streams. There is some built in capabilities in .Net for stream compression, but it will not work with zip archives. You can use SharpZipLib library for that:
Download .nupckg from https://www.nuget.org/packages/SharpZipLib/
Extract files to any folder. You'll need ICSharpCode.SharpZipLib.dll from lib/net45
Below is my simplified translation of their example:
https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#unpack-a-zip-using-zipinputstream-eg-for-unseekable-input-streams
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = ".unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("http://gitlab/test/test1/raw/master/sample.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
It will only extract first entry, you can add a while loop it this sample works.
Here is a snippet with while loop to extract multiple files (put it after $zipEntry = $zipInputStream.GetNextEntry()
on the example above):
While($zipEntry)
$fileName = $zipEntry.Name
Write-Host $fileName
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
Edit
Here is what I found to work...
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("https://github.com/Esri/file-geodatabase-api/raw/master/FileGDB_API_1.5/FileGDB_API_1_5_VS2015.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
1
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
add a comment |
To expand on Mike Twc's answer, a script to do it with and without stream, and compare how long it takes:
$url = "yoururlhere"
function UnzipStream ()
Write-Host "unzipping via stream"
$stopwatch1 = [system.diagnostics.stopwatch]::StartNew()
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip-stream"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead($url)
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
$stopwatch1.Stop()
Write-Host "extraction took $($stopWatch1.ElapsedMilliseconds) millis with stream"
function UnzipWithoutStream()
Write-Host "Extracting without stream"
$stopwatch2 = [system.diagnostics.stopwatch]::StartNew()
$outFolder2 = "unzip-normal"
$wc2 = New-Object System.Net.WebClient
$wc2.DownloadFile($url, "$pwddownload.zip")
$of2 = New-Item -ItemType Directory $outFolder2
Expand-Archive -Path "download.zip" -DestinationPath $of2.FullName
$stopwatch2.Stop()
Write-Host "extraction took $($stopWatch2.ElapsedMilliseconds) millis without stream"
UnzipStream
UnzipWithoutStream
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288109%2fpowershell-unzip-stream%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
OK, turns out zip file doesn't need to be fully downloaded to be decompressed, you can compress/decompress streams. There is some built in capabilities in .Net for stream compression, but it will not work with zip archives. You can use SharpZipLib library for that:
Download .nupckg from https://www.nuget.org/packages/SharpZipLib/
Extract files to any folder. You'll need ICSharpCode.SharpZipLib.dll from lib/net45
Below is my simplified translation of their example:
https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#unpack-a-zip-using-zipinputstream-eg-for-unseekable-input-streams
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = ".unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("http://gitlab/test/test1/raw/master/sample.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
It will only extract first entry, you can add a while loop it this sample works.
Here is a snippet with while loop to extract multiple files (put it after $zipEntry = $zipInputStream.GetNextEntry()
on the example above):
While($zipEntry)
$fileName = $zipEntry.Name
Write-Host $fileName
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
Edit
Here is what I found to work...
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("https://github.com/Esri/file-geodatabase-api/raw/master/FileGDB_API_1.5/FileGDB_API_1_5_VS2015.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
1
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
add a comment |
OK, turns out zip file doesn't need to be fully downloaded to be decompressed, you can compress/decompress streams. There is some built in capabilities in .Net for stream compression, but it will not work with zip archives. You can use SharpZipLib library for that:
Download .nupckg from https://www.nuget.org/packages/SharpZipLib/
Extract files to any folder. You'll need ICSharpCode.SharpZipLib.dll from lib/net45
Below is my simplified translation of their example:
https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#unpack-a-zip-using-zipinputstream-eg-for-unseekable-input-streams
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = ".unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("http://gitlab/test/test1/raw/master/sample.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
It will only extract first entry, you can add a while loop it this sample works.
Here is a snippet with while loop to extract multiple files (put it after $zipEntry = $zipInputStream.GetNextEntry()
on the example above):
While($zipEntry)
$fileName = $zipEntry.Name
Write-Host $fileName
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
Edit
Here is what I found to work...
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("https://github.com/Esri/file-geodatabase-api/raw/master/FileGDB_API_1.5/FileGDB_API_1_5_VS2015.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
1
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
add a comment |
OK, turns out zip file doesn't need to be fully downloaded to be decompressed, you can compress/decompress streams. There is some built in capabilities in .Net for stream compression, but it will not work with zip archives. You can use SharpZipLib library for that:
Download .nupckg from https://www.nuget.org/packages/SharpZipLib/
Extract files to any folder. You'll need ICSharpCode.SharpZipLib.dll from lib/net45
Below is my simplified translation of their example:
https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#unpack-a-zip-using-zipinputstream-eg-for-unseekable-input-streams
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = ".unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("http://gitlab/test/test1/raw/master/sample.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
It will only extract first entry, you can add a while loop it this sample works.
Here is a snippet with while loop to extract multiple files (put it after $zipEntry = $zipInputStream.GetNextEntry()
on the example above):
While($zipEntry)
$fileName = $zipEntry.Name
Write-Host $fileName
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
Edit
Here is what I found to work...
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("https://github.com/Esri/file-geodatabase-api/raw/master/FileGDB_API_1.5/FileGDB_API_1_5_VS2015.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
OK, turns out zip file doesn't need to be fully downloaded to be decompressed, you can compress/decompress streams. There is some built in capabilities in .Net for stream compression, but it will not work with zip archives. You can use SharpZipLib library for that:
Download .nupckg from https://www.nuget.org/packages/SharpZipLib/
Extract files to any folder. You'll need ICSharpCode.SharpZipLib.dll from lib/net45
Below is my simplified translation of their example:
https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#unpack-a-zip-using-zipinputstream-eg-for-unseekable-input-streams
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = ".unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("http://gitlab/test/test1/raw/master/sample.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
It will only extract first entry, you can add a while loop it this sample works.
Here is a snippet with while loop to extract multiple files (put it after $zipEntry = $zipInputStream.GetNextEntry()
on the example above):
While($zipEntry)
$fileName = $zipEntry.Name
Write-Host $fileName
$buffer = New-Object byte 4096
$sw = [System.IO.File]::Create("$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
Edit
Here is what I found to work...
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead("https://github.com/Esri/file-geodatabase-api/raw/master/FileGDB_API_1.5/FileGDB_API_1_5_VS2015.zip")
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
edited Nov 16 '18 at 23:12
tacos_tacos_tacos
5,886855107
5,886855107
answered Nov 15 '18 at 22:58
Mike TwcMike Twc
1,111312
1,111312
1
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
add a comment |
1
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
1
1
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
Awesome! I had to tweak a bit to get it to work, but that's the idea. I'll share my tweak in an edit
– tacos_tacos_tacos
Nov 16 '18 at 23:11
add a comment |
To expand on Mike Twc's answer, a script to do it with and without stream, and compare how long it takes:
$url = "yoururlhere"
function UnzipStream ()
Write-Host "unzipping via stream"
$stopwatch1 = [system.diagnostics.stopwatch]::StartNew()
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip-stream"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead($url)
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
$stopwatch1.Stop()
Write-Host "extraction took $($stopWatch1.ElapsedMilliseconds) millis with stream"
function UnzipWithoutStream()
Write-Host "Extracting without stream"
$stopwatch2 = [system.diagnostics.stopwatch]::StartNew()
$outFolder2 = "unzip-normal"
$wc2 = New-Object System.Net.WebClient
$wc2.DownloadFile($url, "$pwddownload.zip")
$of2 = New-Item -ItemType Directory $outFolder2
Expand-Archive -Path "download.zip" -DestinationPath $of2.FullName
$stopwatch2.Stop()
Write-Host "extraction took $($stopWatch2.ElapsedMilliseconds) millis without stream"
UnzipStream
UnzipWithoutStream
add a comment |
To expand on Mike Twc's answer, a script to do it with and without stream, and compare how long it takes:
$url = "yoururlhere"
function UnzipStream ()
Write-Host "unzipping via stream"
$stopwatch1 = [system.diagnostics.stopwatch]::StartNew()
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip-stream"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead($url)
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
$stopwatch1.Stop()
Write-Host "extraction took $($stopWatch1.ElapsedMilliseconds) millis with stream"
function UnzipWithoutStream()
Write-Host "Extracting without stream"
$stopwatch2 = [system.diagnostics.stopwatch]::StartNew()
$outFolder2 = "unzip-normal"
$wc2 = New-Object System.Net.WebClient
$wc2.DownloadFile($url, "$pwddownload.zip")
$of2 = New-Item -ItemType Directory $outFolder2
Expand-Archive -Path "download.zip" -DestinationPath $of2.FullName
$stopwatch2.Stop()
Write-Host "extraction took $($stopWatch2.ElapsedMilliseconds) millis without stream"
UnzipStream
UnzipWithoutStream
add a comment |
To expand on Mike Twc's answer, a script to do it with and without stream, and compare how long it takes:
$url = "yoururlhere"
function UnzipStream ()
Write-Host "unzipping via stream"
$stopwatch1 = [system.diagnostics.stopwatch]::StartNew()
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip-stream"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead($url)
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
$stopwatch1.Stop()
Write-Host "extraction took $($stopWatch1.ElapsedMilliseconds) millis with stream"
function UnzipWithoutStream()
Write-Host "Extracting without stream"
$stopwatch2 = [system.diagnostics.stopwatch]::StartNew()
$outFolder2 = "unzip-normal"
$wc2 = New-Object System.Net.WebClient
$wc2.DownloadFile($url, "$pwddownload.zip")
$of2 = New-Item -ItemType Directory $outFolder2
Expand-Archive -Path "download.zip" -DestinationPath $of2.FullName
$stopwatch2.Stop()
Write-Host "extraction took $($stopWatch2.ElapsedMilliseconds) millis without stream"
UnzipStream
UnzipWithoutStream
To expand on Mike Twc's answer, a script to do it with and without stream, and compare how long it takes:
$url = "yoururlhere"
function UnzipStream ()
Write-Host "unzipping via stream"
$stopwatch1 = [system.diagnostics.stopwatch]::StartNew()
Add-Type -Path ".ICSharpCode.SharpZipLib.dll"
$outFolder = "unzip-stream"
$wc = [System.Net.WebClient]::new()
$zipStream = $wc.OpenRead($url)
$zipInputStream = [ICSharpCode.SharpZipLib.Zip.ZipInputStream]::New($zipStream)
$zipEntry = $zipInputStream.GetNextEntry()
while($zipEntry)
if (-Not($zipEntry.IsDirectory))
$fileName = $zipEntry.Name
$buffer = New-Object byte 4096
$filePath = "$pwd$outFolder$fileName"
$parentPath = "$filePath.."
Write-Host $parentPath
if (-Not (Test-Path $parentPath))
New-Item -ItemType Directory $parentPath
$sw = [System.IO.File]::Create("$pwd$outFolder$fileName")
[ICSharpCode.SharpZipLib.Core.StreamUtils]::Copy($zipInputStream, $sw, $buffer)
$sw.Close()
$zipEntry = $zipInputStream.GetNextEntry()
$stopwatch1.Stop()
Write-Host "extraction took $($stopWatch1.ElapsedMilliseconds) millis with stream"
function UnzipWithoutStream()
Write-Host "Extracting without stream"
$stopwatch2 = [system.diagnostics.stopwatch]::StartNew()
$outFolder2 = "unzip-normal"
$wc2 = New-Object System.Net.WebClient
$wc2.DownloadFile($url, "$pwddownload.zip")
$of2 = New-Item -ItemType Directory $outFolder2
Expand-Archive -Path "download.zip" -DestinationPath $of2.FullName
$stopwatch2.Stop()
Write-Host "extraction took $($stopWatch2.ElapsedMilliseconds) millis without stream"
UnzipStream
UnzipWithoutStream
answered Nov 16 '18 at 23:32
tacos_tacos_tacostacos_tacos_tacos
5,886855107
5,886855107
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288109%2fpowershell-unzip-stream%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't think the .zip compression file format works like that. (A partial download of a .zip file is a corrupt .zip file.)
– Bill_Stewart
Nov 13 '18 at 21:14
1
@Bill_Stewart is 100% right. The index is at the end of a zip called the central directory. Its where the metadeta but most importantly where the start point index of each file stored.
– ArcSet
Nov 14 '18 at 0:02
@ArcSet , @Bill_Stewart yes I have read this as well but I have also been able to do something like this in
nodejs
even if it is a bit hackerrific. So maybe try a compression format that better supports streaming decompression?– tacos_tacos_tacos
Nov 14 '18 at 0:10
Is that file on a network drive or ftp or sharepoint? Can you share that node js script?
– Mike Twc
Nov 14 '18 at 4:35
@MikeTwc sure, ill gist it, but for now just see github.com/mhr3/unzip-stream - i use this library
– tacos_tacos_tacos
Nov 14 '18 at 7:57