-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.ps1
35 lines (31 loc) · 1.17 KB
/
split.ps1
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
function split($path, $chunkSize=52428800)
{
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($path)
# $directory = [System.IO.Path]::GetDirectoryName($path)
$directory = (Get-Item .).FullName
$extension = [System.IO.Path]::GetExtension($path)
$file = New-Object System.IO.FileInfo($path)
$totalChunks = [int]($file.Length / $chunkSize) + 1
$digitCount = [int][System.Math]::Log10($totalChunks) + 1
$reader = [System.IO.File]::OpenRead($path)
$count = 0
$buffer = New-Object Byte[] $chunkSize
$hasMore = $true
while($hasMore)
{
$bytesRead = $reader.Read($buffer, 0, $buffer.Length)
$chunkFileName = "$directory\$fileName$extension.{0:D$digitCount}.part"
$chunkFileName = $chunkFileName -f $count
$output = $buffer
if ($bytesRead -ne $buffer.Length)
{
$hasMore = $false
$output = New-Object Byte[] $bytesRead
[System.Array]::Copy($buffer, $output, $bytesRead)
}
[System.IO.File]::WriteAllBytes($chunkFileName, $output)
++$count
}
$reader.Close()
}
split "InstallTinyTexAndPackages.zip"