RE: [Help] What is the best way to read binary file ??
I have a helper script written by Volv that works with binary data. I'll post/attach when I get home.
These should help.
JScript code:function binReadFile(filePath)
{
var fstream = new ActiveXObject("ADODB.Stream");
fstream.Type = 1;
fstream.Open;
fstream.LoadFromFile(filePath);
return fstream.Read;
}
function binWriteFile(binData, filePath)
{
var fstream = new ActiveXObject("ADODB.Stream");
fstream.Type = 1;
fstream.Open;
fstream.Write(binData);
fstream.SaveToFile(filePath, 2);
fstream.Close;
}
function asciiReadFile(filePath)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var contents = fso.OpenTextFile(filePath, 1, 0).ReadAll();
return contents;
}
function asciiWriteFile(strData, filePath)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var txtfile = fso.CreateTextFile(filePath, true);
txtfile.Write(strData);
txtfile.close();
}
function GetFileSize(filePath)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(filePath)) {
var file = fso.getFile(filePath);
return file.size;
} else {
return -1;
}
}
This post was edited on 04-19-2009 at 03:32 AM by MeEtc.