Write binary file with Javascript and ADODB.Stream

7.5k Views Asked by At

I'm currently making a HTA application and I need to save Base64-encoded ZIP archive to file.

var stream = new ActiveXObject('ADODB.Stream');
stream.Type = 1;
stream.Open();
stream.Write(atob(data));
stream.SaveToFile('dump.zip');
stream.Close();    

This code throw error on stream.Write(data) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. There are some solutions for VBScript, but I'm trying to make it on javascript.

1

There are 1 best solutions below

1
On BEST ANSWER

Thanks to this post

var stream = new ActiveXObject('ADODB.Stream');
stream.Type = 2; //Stream type - text data o_0
stream.Charset = "windows-1251"; //windows-1252 works too
stream.Write(atob(data));
stream.SaveToFile('dump.zip');
stream.Close(); 

I still don't understand why I must save binary data as text, but it works.