36 lines
1.2 KiB
PowerShell
36 lines
1.2 KiB
PowerShell
$SourceFilePath = $args[0]
|
|
$ChunkSize = $args[1]
|
|
$Offset = $args[2]
|
|
|
|
# Function to create chunk file
|
|
function Create-ChunkFile {
|
|
param (
|
|
[byte[]]$ChunkData,
|
|
[int]$ChunkNumber
|
|
)
|
|
|
|
$chunkFileName = Join-Path $subDir ("{0}_{1:D5}.bin" -f [System.IO.Path]::GetFileNameWithoutExtension($SourceFilePath), $ChunkNumber)
|
|
[System.IO.File]::WriteAllBytes($chunkFileName, $ChunkData)
|
|
}
|
|
|
|
# Create subdirectory named after the source file (without extension) for chunks
|
|
$subDir = Join-Path ([System.IO.Path]::GetDirectoryName($SourceFilePath)) ([System.IO.Path]::GetFileNameWithoutExtension($SourceFilePath))
|
|
if (!(Test-Path -Path $subDir)) {
|
|
New-Item -ItemType Directory -Path $subDir
|
|
}
|
|
|
|
# Read the binary data from the file
|
|
$data = [System.IO.File]::ReadAllBytes($SourceFilePath)
|
|
$dataLength = $data.Length
|
|
$chunkNumber = 0
|
|
|
|
# Adjust the start position based on the offset
|
|
$startPosition = [Math]::Min($Offset, $dataLength)
|
|
|
|
# Process chunks
|
|
for ($i = $startPosition; $i -lt $dataLength; $i += $ChunkSize) {
|
|
$chunkEnd = [Math]::Min($i + $ChunkSize, $dataLength)
|
|
$chunkData = $data[$i..($chunkEnd - 1)]
|
|
Create-ChunkFile -ChunkData $chunkData -ChunkNumber $chunkNumber
|
|
$chunkNumber++
|
|
}
|