想要将文件拆分成 block 的原因有很多 - 主要是为了网络传输(例如电子邮件附件),但我确信有些场景可能需要我无法想象的事情。 那么如何将文件拆分成可以轻松组装回原始文件(包括非 Windows 系统)的 block ?
什么是可能性:
- MAKECAB - 内置的 Windows 归档器 - 它可以压缩文件和 拆分它,但很难在非 Windows 上组装文件 机。
- WSH/Jscript/VBscript - 可以使用 ADODB 轻松处理二进制文件 Streams。据我所知,JScript 更可取。
- .NET/JScript.net/VB/C# - 因为 .NET 带有命令行编译器 它也可以用于此目的。 .NET 二进制流可能 在这种情况下是它可以提供的最好的。
- CERTUTIL - 因为它可以将二进制文件转换为 HEX 并返回它 可以使用批处理文件处理 HEX 数据并拆分文件 成 block 。
可能也可以使用 GZipStreams,因为它们允许 读取字节(并提供可移植压缩!)。如果有人成功了(或 提供任何其他方法):-)
最佳答案
前段时间我为此编写了一个名为 BinToBat.bat 的 Batch-JScript 混合脚本。这是它的帮助屏幕:
Create an installer Batch program for data files of any type
BINTOBAT [/T:.ext1.ext2...] [/L:lineSize] [/F[:fileSize]] filename ...
/T:.ext1.ext2 Specify the extensions of text type files that will not be
encoded as hexadecimal digits, but preserved as text.
/L:lineSize Specify the size of output lines (default: 78).
/F[:fileSize] /F switch specify to generate a Full installer file.
The optional fileSize specify the maximum output file size.
BinToBat encode the given data files as hexadecimal digits (or preserve they
as compressed text) and insert they into InstallFiles.bat program; when this
program run, it generates the original data files.
You may rename the InstallFiles.bat program as you wish, but preserving the
"Install" prefix is suggested.
You may use wild-cards in the filename list.
If the /F switch is not given, a Partial installer is created:
- You may insert a short description for each file.
- You may insert divisions in the file listing via a dash in the parameters.
- The installer allows to select which files will be downloaded and ask
before overwrite existent files.
If the /F switch is given, a Full installer is created:
- The installer always download all files.
- You may specify commands that will be executed after the files were copied.
- You may specify the maximum size of the output file via /F:fileFize, so in
this case the output file will be divided in parts with a numeric postfix.
If you use /F switch you can NOT rename the InstallFiles??.bat files; the
first one is the installer and the rest just contain data.
您可以从this site 下载BinToBat.bat 程序。 .
关于.net - 如何在没有外部软件的情况下使用批处理脚本将二进制文件拆分为一定大小的 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28244063/