global type f_writefile from function_object
end type
forward prototypes
global function integer f_writefile (string filename, ref blob fb, boolean bappend)
end prototypes
global function integer f_writefile (string filename, ref blob fb, boolean bappend);int result,fnum,loops,i;
long flen, bytes_read, new_pos
Blob b;
/////////////////////////////
IF ISNULL(b) THEN
MessageBox("错误","no Data need To write to file(blob is null)!",INFORMATION!);
GOTO ERROR;
END IF
// Get the file length, and open the file
flen = len(fb);
// Determine how many times to call FileRead
IF (flen <=0) THEN
// MessageBox("Error","no Data need To write to file(blob=0)!",INFORMATION!);
GOTO ERROR;
END IF
if bAppend then
fnum = FileOpen(filename,StreamMode!, Write!, LockWrite!,Append!);
else
fnum = FileOpen(fileName,StreamMode!,write!,LockWrite!,Replace!);
end if
IF (fnum <1) THEN
MessageBox("打开文件错误","不能打开目标文件~r~n"+fileName);
GOTO ERROR;
END IF
IF flen > 32765 THEN
IF Mod(flen, 32765) = 0 THEN
loops = flen/32765
ELSE
loops = (flen/32765) + 1
END IF
ELSE
loops = 1
END IF
////****** Read the file ******//
new_pos = 1
FOR i = 1 to loops
b = Blobmid(fb,new_pos,32765);
bytes_read = FileWrite(fnum, b)
new_pos +=bytes_read;
NEXT
FileClose(fnum);
////////////////////////////
RETURN 1; //***** Return 1 As Successful;
ERROR:
Return -1; //***** Return -1 As Failure