Storing large file within batch file

2019-08-28 02:59发布

I'm trying to create a batch file that stores one or more large files within it as base64 encoded strings, then converts them back into files. I've been following the first answer on this question: Store a file inside of a batch file? but i'm trying to store a ~3mb file within this batch file, and when it comes to writing the files source back to a file (via echo), the batch file appears to crash. I get a popup saying 'Windows Command Processor has stopped working'.

Is there a limit to how much data batch files can write to a file in one go?

I've followed the example correctly, only changing the file.tmp name to filetest.tmp, but there are around 47,000 lines in this batch file (which is probably what's causing it to crash).

Any idea on how to get around this?

Edit: certutil encoded the original files quite fast, so I assume that part is not the issue.

1条回答
Bombasti
2楼-- · 2019-08-28 03:40

I suggest you to review the last version of my Binary to Batch encoding program: BinToBat.bat; it have a series of very useful features for this type of encoding. This is the help screen:

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 program has been successfully tested with files of 15 MB size, that are encoded in a reasonable time (8-9 minutes) and extracted even faster. Of course, these times depends on the computer used.

查看更多
登录 后发表回答