I found a way by myself.
Since psfa
is a byte array, simply the number of the elements represents its size.
msgbox % psfa.maxindex() + 1 ; 17223 bytes for the example file. A COM array is zero-based so it needs to add one.
However, to save the binary data stored in a safearray, using the file object was not successful. (There might be a way but I could not find it) Instead, ADODB.Stream
worked like a charm.
strURL := "http://www.mozilla.org/media/img/sandstone/buttons/firefox-large.png"
strFilePath := A_ScriptDir "\dl.png"
bOverWrite := true
pwhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
pwhr.Open("GET", strURL)
pwhr.Send()
if (psfa := pwhr.ResponseBody ) {
pstm := ComObjCreate("ADODB.Stream")
pstm.Type() := 1 ; 1: binary 2: text
pstm.Open()
pstm.Write(psfa)
pstm.SaveToFile(strFilePath, bOverWrite ? 2 : 1)
pstm.Close()
}