在 Powershell 中,如何拆分大型二进制文件? [英] In Powershell, How do I split a large binary file?
本文介绍了在 Powershell 中,如何拆分大型二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在别处看到了文本文件的答案,但我需要为压缩文件执行此操作.
I've seen the answer elsewhere for text files, but I need to do this for a compressed file.
我有一个 6G 的二进制文件,需要拆分为 100M 的块.我是否在某处错过了 unix 的头"的模拟?
I've got a 6G binary file which needs to be split into 100M chunks. Am I missing the analog for unix's "head" somewhere?
推荐答案
没关系.给你:
function split($inFile, $outPrefix, [Int32] $bufSize){
$stream = [System.IO.File]::OpenRead($inFile)
$chunkNum = 1
$barr = New-Object byte[] $bufSize
while( $bytesRead = $stream.Read($barr,0,$bufsize)){
$outFile = "$outPrefix$chunkNum"
$ostream = [System.IO.File]::OpenWrite($outFile)
$ostream.Write($barr,0,$bytesRead);
$ostream.close();
echo "wrote $outFile"
$chunkNum += 1
}
}
假设:bufSize 适合内存.
Assumption: bufSize fits in memory.
这篇关于在 Powershell 中,如何拆分大型二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文