I've been a whole day looking for a way to read a binary file from the local file system, do some modifications to it and save it back to disk. The script must be run on batch, since other scripts must be run afterwards.
Reading is not an issue: you can always read it as text, and then convert the characters to bytes. The problem is writting it to disk. ActiveXObject("Scripting.FileSystemObject") facility can't be used, since some bytes don't map to characters and then Write methods throw an exception.
I've read a post, somewhere else suggesting to use ADODB.Stream and this is as far as I can go:
var foo = ...
var stream = new ActiveXObject('ADODB.Stream');
stream.Type = 1; //Means "binary".
stream.Open();
stream.Write(foo);
stream.SaveToFile('C:\\foo.bin', 2); //2 means save/create/overwrite
Regardles of which type of variable I put in foo, Windows Script Host claims:
Error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
Code: 800A0BB9
Source: ADODB.Stream
It seems that ADODB Stream.Write method expects A Variant that contains an array of bytes to be written. Since such things doesn't exist in Javascript, I tried with an array filled with numbers, a string, a single number, a single char, an hex expression... I've found VBArray but you can't actually write anything in those.
Does anybody know which type must be used? Or any other mean to save binary data?