$PBExportHeader$f_saveblobtofile.srf
global type f_saveblobtofile from function_object
end type

forward prototypes
global function integer f_saveblobtofile (blob arg_bdata, string arg_filename, ref string arg_msg)
end prototypes

global function integer f_saveblobtofile (blob arg_bdata, string arg_filename, ref string arg_msg);//f_saveblobtofile(arg_bdata,arg_filename,arg_msg)
long rslt=1
long fend,li_FileNum,fend_t,ls_i,ls_jh

blob b_dtdata_p
 
//if len(b_dtdata)32765
fend=lena(arg_bdata)
if fend<=32765 then
	fend_t=1
else
	fend_t=fend/32765
	if mod(fend,32765)<>0 then
		fend_t=fend_t+1
	end if
end if
li_FileNum = FileOpen( arg_filename,StreamMode!, Write!, LockWrite!)
if li_FileNum<=0 then
	arg_msg="打开文件"+arg_filename+"失败"
	rslt=0
	fileclose(li_FileNum)
	goto ext
end if
for ls_i = 1 to fend_t
	b_dtdata_p=blobmid(arg_bdata,1+(ls_i - 1 )*32765,32765)

	ls_jh=FileWrite(li_FileNum, b_dtdata_p)
	if ls_jh<=0 then
		arg_msg="写文件"+arg_filename+"失败"
		rslt=0
		fileclose(li_FileNum)
		goto ext
	end if
next

fileclose(li_FileNum)
ext:

return rslt
end function

