.net - 如何在没有外部软件的情况下使用批处理脚本将二进制文件拆分为一定大小的 block ?

标签 .net split jscript batch-file

想要将文件拆分成 block 的原因有很多 - 主要是为了网络传输(例如电子邮件附件),但我确信有些场景可能需要我无法想象的事情。 那么如何将文件拆分成可以轻松组装回原始文件(包括非 Windows 系统)的 block ?

什么是可能性:

  1. MAKECAB - 内置的 Windows 归档器 - 它可以压缩文件和 拆分它,但很难在非 Windows 上组装文件 机。
  2. WSH/Jscript/VBscript - 可以使用 ADODB 轻松处理二进制文件 Streams。据我所知,JScript 更可取。
  3. .NET/JScript.net/VB/C# - 因为 .NET 带有命令行编译器 它也可以用于此目的。 .NET 二进制流可能 在这种情况下是它可以提供的最好的。
  4. 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/

相关文章:

c# - 使用 System.Type 调用泛型方法

python - 根据条件拆分 pandas 数据帧列中特殊字符上的字符串

python - 通过 Bokeh 交互式突出显示时间序列的特定范围

vba - MSXML2.ServerXMLHTTP 客户端证书

javascript - Videojs 上的奇怪错误

.net - 仅在部署的PresentationFramework 中发生XmlParseException

.net - .Net异步套接字操作限制?

.net - Delphi 和 Delphi.NET 之间的区别

python - 在 python 中拆分项目并附加一些项目

javascript - 在每个图像标签之前拆分 HTML