forked from bazel-contrib/rules_python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzip.ps1
More file actions
45 lines (38 loc) · 1.4 KB
/
zip.ps1
File metadata and controls
45 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
param (
[Parameter(Position=0, Mandatory=$true)]
[string]$Output,
[Parameter(Position=1, Mandatory=$true)]
[string]$Root
)
Add-Type -AssemblyName System.IO.Compression
$fixedTime = [datetime]"1980-01-01T00:00:00"
$RootFull = (Resolve-Path $Root).Path
$stream = [System.IO.File]::Open($Output, [System.IO.FileMode]::Create)
try {
$archive = [System.IO.Compression.ZipArchive]::new($stream, [System.IO.Compression.ZipArchiveMode]::Create)
try {
$files = Get-ChildItem -Path $RootFull -Recurse -File
foreach ($file in $files) {
# Relativize path and normalize separators
$relPath = $file.FullName.Substring($RootFull.Length).TrimStart('\', '/')
$relPath = $relPath -replace '\\', '/'
$entry = $archive.CreateEntry($relPath, [System.IO.Compression.CompressionLevel]::NoCompression)
$entry.LastWriteTime = $fixedTime
$entryStream = $entry.Open()
try {
$fileStream = [System.IO.File]::OpenRead($file.FullName)
try {
$fileStream.CopyTo($entryStream)
} finally {
$fileStream.Dispose()
}
} finally {
$entryStream.Dispose()
}
}
} finally {
$archive.Dispose()
}
} finally {
$stream.Dispose()
}